本文整理汇总了C++中QLocale::toDate方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocale::toDate方法的具体用法?C++ QLocale::toDate怎么用?C++ QLocale::toDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLocale
的用法示例。
在下文中一共展示了QLocale::toDate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stringToDate
void Globalization::stringToDate(int scId, int ecId, const QVariantMap &options) {
QString dateString = options.find("dateString")->toString();
Globalization::Format formatLength = static_cast<Globalization::Format>(options.find("formatLength")->toInt());
Globalization::Selector selector = static_cast<Globalization::Selector>(options.find("selector")->toInt());
QLocale::FormatType format = translateFormat(formatLength);
QLocale locale;
bool valid(true);
int year(0), month(0), day(0), hour(0), minute(0), second(0), millisecond(0);
switch (selector) {
case SELECTOR_ALL:
{
QDateTime dateTime = locale.toDateTime(dateString, format);
valid = dateTime.isValid();
QTime time = dateTime.time();
hour = time.hour(); minute = time.minute(); second = time.second(); millisecond = time.msec();
QDate date = dateTime.date();
year = date.year(); month = date.month(); day = date.day();
}
break;
case SELECTOR_TIME:
{
QTime time = locale.toTime(dateString, format);
valid = time.isValid();
hour = time.hour(); minute = time.minute(); second = time.second(); millisecond = time.msec();
}
break;
case SELECTOR_DATE:
{
QDate date = locale.toDate(dateString, format);
valid = date.isValid();
year = date.year(); month = date.month(); day = date.day();
}
break;
}
if ((format == QLocale::NarrowFormat || format == QLocale::ShortFormat) && year < 2000 && year > 1900) {
year += 100;
}
if (!valid) {
this->callback(ecId, QString("new GlobalizationError(%1, 'parsing error')").arg(Globalization::PARSING_ERROR));
} else {
QVariantMap obj;
obj.insert("year", year);
obj.insert("month", month - 1);
obj.insert("day", day);
obj.insert("hour", hour);
obj.insert("minute", minute);
obj.insert("second", second);
obj.insert("millisecond", millisecond);
this->cb(scId, obj);
}
}
示例2: date
QValidator::State KDateValidator::date(const QString &text, QDate &d) const
{
QLocale::FormatType formats[] = { QLocale::LongFormat, QLocale::ShortFormat, QLocale::NarrowFormat };
QLocale locale;
for (int i = 0; i < 3; i++) {
QDate tmp = locale.toDate(text, formats[i]);
if (tmp.isValid()) {
d = tmp;
return Acceptable;
}
}
return QValidator::Intermediate;
}
示例3: method_fromLocaleDateString
QV4::ReturnedValue QQmlDateExtension::method_fromLocaleDateString(QV4::CallContext *ctx)
{
QV4::ExecutionEngine * const engine = ctx->d()->engine;
if (ctx->argc() == 1 && ctx->args()[0].isString()) {
QLocale locale;
QString dateString = ctx->args()[0].stringValue()->toQString();
QDate date = locale.toDate(dateString);
return QV4::Encode(engine->newDateObject(QDateTime(date)));
}
if (ctx->argc() < 1 || ctx->argc() > 3 || !isLocaleObject(ctx->args()[0]))
V4THROW_ERROR("Locale: Date.fromLocaleDateString(): Invalid arguments");
QV4::Scope scope(ctx);
GET_LOCALE_DATA_RESOURCE(ctx->args()[0]);
QLocale::FormatType enumFormat = QLocale::LongFormat;
QDate dt;
QString dateString = ctx->args()[1].toQStringNoThrow();
if (ctx->argc() == 3) {
if (ctx->args()[2].isString()) {
QString format = ctx->args()[2].stringValue()->toQString();
dt = r->d()->locale.toDate(dateString, format);
} else if (ctx->args()[2].isNumber()) {
quint32 intFormat = ctx->args()[2].toNumber();
QLocale::FormatType format = QLocale::FormatType(intFormat);
dt = r->d()->locale.toDate(dateString, format);
} else {
V4THROW_ERROR("Locale: Date.fromLocaleDateString(): Invalid datetime format");
}
} else {
dt = r->d()->locale.toDate(dateString, enumFormat);
}
return QV4::Encode(engine->newDateObject(QDateTime(dt)));
}
示例4: validate
QValidator::State DatePickerValidator::validate(QString& text, int&) const
{
QLocale::FormatType formats[] =
{
QLocale::LongFormat,
QLocale::ShortFormat,
QLocale::NarrowFormat
};
QLocale locale = m_picker->locale();
for (int i = 0; i < 3; i++)
{
QDate tmp = locale.toDate(text, formats[i]);
if (tmp.isValid())
{
return Acceptable;
}
}
return QValidator::Intermediate;
}