Qvariant无法区分QDATETIME和QSTRINT
QVariant is not able to distinguish between QDateTime and QString
我有一个我存储在 QVariant
中的 QDateTime object
,然后用 type()
检查 QVariant
void MainWindow::Test()
{
QDateTime myDate; // QDateTime;
myDate.setDate(QDate::currentDate());
QVariant myVariant(myDate);
qDebug() << myVariant.canConvert(QMetaType::QDateTime); // return true
// here is the problem
qDebug() << myVariant.canConvert(QMetaType::QString); // return true as well
}
canConvert
仅表示转换是可能的,而不是变体包含特定类型。验证类型使用此方法:
qDebug() << (myVariant.type()==QVariant::DateTime);
qDebug() << (myVariant.type()==QVariant::String);
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- QDateTime::toString() 在退出处理程序中使用时失败
- 使用qdatetime-无法将图像写入路径
- QDateTime::secsTo 为不同的 QDateTime 返回相同的值
- 我如何以不同的语言从qdatetime获取日名
- 如何从字符串创建固定的QDateTime
- 将 QDateTime 作为指针传递
- 无法将参数 1 从 QDateTime 转换为 'tTimeMods'
- Qvariant无法区分QDATETIME和QSTRINT
- QDateTime::fromMSecsSinceEpoch无法正常工作
- Qt将时间和日期字符串转换为带时区的QDateTime
- 将系统::Datetime转换为QDateTime
- QDateTime类中缺少addMinutes的原因
- QDateTime Isodate with timezone ?
- 如何获取Qt中两个QDatetime之间创建的所有文件的文件路径?
- 如何将QDateTime转换为GMT Unix Stamp
- QDateTime::fromstring( __DATE__, "MMM d yyyy" ) 返回无效
- QDateTime::fromString返回无效日期,我缺少什么
- Qt. QDateTime具有时区和附加秒的不可预测行为
- QDateTime with sqlite3