本文整理汇总了C++中QLocale::toDateTime方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocale::toDateTime方法的具体用法?C++ QLocale::toDateTime怎么用?C++ QLocale::toDateTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLocale
的用法示例。
在下文中一共展示了QLocale::toDateTime方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: method_fromLocaleString
QV4::ReturnedValue QQmlDateExtension::method_fromLocaleString(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();
QDateTime dt = locale.toDateTime(dateString);
return QV4::Encode(engine->newDateObject(dt));
}
QV4::Scope scope(ctx);
if (ctx->argc() < 1 || ctx->argc() > 3 || !isLocaleObject(ctx->args()[0]))
V4THROW_ERROR("Locale: Date.fromLocaleString(): Invalid arguments");
GET_LOCALE_DATA_RESOURCE(ctx->args()[0]);
QLocale::FormatType enumFormat = QLocale::LongFormat;
QDateTime 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.toDateTime(dateString, format);
} else if (ctx->args()[2].isNumber()) {
quint32 intFormat = ctx->args()[2].toNumber();
QLocale::FormatType format = QLocale::FormatType(intFormat);
dt = r->d()->locale.toDateTime(dateString, format);
} else {
V4THROW_ERROR("Locale: Date.fromLocaleString(): Invalid datetime format");
}
} else {
dt = r->d()->locale.toDateTime(dateString, enumFormat);
}
return QV4::Encode(engine->newDateObject(dt));
}
示例3: replyFinished
void WPUtils::replyFinished(QNetworkReply *rep)
{
QVariantMap _res_bck;
model = new GroupDataModel(QStringList() << "sortDate" ); //"date" << "date_created_gmt" << "post_date");
model->setSortedAscending(false);
model->setGrouping(ItemGrouping::None);
if ( model && !model->isEmpty() )
model->clear();
if ( !res.isEmpty() )
res.clear();
if (!_res_bck.isEmpty() )
_res_bck.clear();
QByteArray ret = rep->readAll();
if ( !ret.isEmpty() )
qDebug() << "reading " << ret; //rep->readAll();
else qDebug() << "ret empty -> error handling /*TODO*/";
QString _current_name = "";
QXmlStreamReader xml(ret);
QList<QVariantMap> Entries;
int _struct_counter = 0;
while(!xml.atEnd() && !xml.hasError()) {
QXmlStreamReader::TokenType token = xml.readNext();
if ( token == QXmlStreamReader::StartElement )
{
if ( xml.name().toString() == "fault")
{
res["ERROR"] = "fault";
} else if ( xml.name().toString() == "struct" )
{
_struct_counter++;
} else if ( xml.name().toString() == "name" )
{
token = xml.readNext();
_current_name = xml.text().toString();
} else if ( xml.name().toString() == "value" && !_current_name.isEmpty() )
{
token = xml.readNext();
if ( xml.name().toString() == "string" || xml.name().toString() == "boolean" || xml.name().toString() == "dateTime.iso8601" )
{
token = xml.readNext();
if ( _current_name == "post_date" || _current_name == "date_created_gmt" )
{
QLocale c = QLocale::c();
QDateTime date = c.toDateTime(xml.text().toString(), QLatin1String("yyyyMMddTHH:mm:ss"));//ddd, dd MMM yyyy HH:mm:ss"));// '+0000"));
QString outputFromat("dd MMM yyyy - HH:mm:ss");
date.setTimeSpec(Qt::UTC);
res["sortDate"] = date;
res["date"] = date.toString(outputFromat);
/* is this insane?! */
/*
QString theDate = xml.text().toString(); //"20130503T14:48:55";
QDateTime date = QDateTime::fromString(theDate, "yyyyMMddTHH:mm:ss");
res["sortDate"] = date;
res["date"] = date.toString(Qt::SystemLocaleShortDate);
*/
}
else res[_current_name] = xml.text().toString();
_current_name = "";
} else _current_name = "";
} else if ( xml.name().toString() == "string" )
{
/* newpost workaround */
token = xml.readNext();
res["newpostid"] = xml.text().toString();
model->insert(res);
_res_bck.unite(res);
res.clear();
} else if ( xml.name().toString() == "boolean")
{
/* deletepost workaround */
token = xml.readNext();
res["delpost"] = xml.text().toString();
model->insert(res);
_res_bck.unite(res);
res.clear();
} else if ( xml.name().toString() == "int" )
{
/* newcomment workaround */
token = xml.readNext();
res["newcommentid"] = xml.text().toString();
model->insert(res);
_res_bck.unite(res);
res.clear();
}
QVariantMap Entry;
foreach(const QXmlStreamAttribute &attr, xml.attributes()) {
qDebug() << "adding name = " << attr.name().toString() << " value = " << attr.value().toString();
//.........这里部分代码省略.........