我现在,这个问题听起来很傻,但我就是不能让它起作用。最糟糕的例子:
QString time_format = "yyyy-MM-dd HH:mm:ss";
QDateTime a = QDateTime::currentDateTime();
QString as = a.toString(time_format);
qDebug() << as; // print "2014-07-16 17:47:04"
QDateTime b;
b.fromString(as,time_format);
assert(b.isValid()); // fails我创建了一个有效的QDatetime,创建了一个字符串(这是正确的),并再次尝试将其转换为QDatetime (使用相同的time_format- string )。但是突然之间,字符串不能被解析了。
有什么想法吗?
发布于 2014-07-16 23:57:13
fromString是一个返回日期的静态函数,因此您需要执行以下操作:
QDateTime b = QDateTime::fromString(as,time_format);在您的代码中,b从未改变过它的默认初始化状态
发布于 2018-09-07 21:14:52
QString as = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");https://stackoverflow.com/questions/24785183
复制相似问题