I have a QDateTime object
which I store in a QVariant
and then I check the QVariant
with type()
but it behaves strangely when I check the type.
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
means only that conversion is possible, not that variant contains specific type. To verify type use this approach: