Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.2.12, 6.5.5-1, 6.7.0
-
Windows 10 22H2, MSVC 2019
-
26a81bd4f (dev), 843b0b819 (6.7), 626f132a5 (tqtc/lts-6.5)
Description
Code
#include <QtTest> class VariantNullTest : public QObject { Q_OBJECT const QDate validDate = QDate(2024, 05, 06); private slots: void initialiazeDataByConstructor() { QVariant v(validDate); QCOMPARE(v.toString(), "2024-05-06"); QCOMPARE(v.isNull(), false); QCOMPARE(v.isValid(), true); } void initialiazeDataFromValue() { QVariant v = QVariant::fromValue(validDate); QCOMPARE(v.toString(), "2024-05-06"); QCOMPARE(v.isNull(), false); QCOMPARE(v.isValid(), true); } #if QT_VERSION_MAJOR >= 6 void initializeDataFromType() { QVariant v(QMetaType::fromType<QDate>(), &validDate); QCOMPARE(v.toString(), "2024-05-06"); QCOMPARE(v.isNull(), false); QCOMPARE(v.isValid(), true); } #endif void storeDataInInvalidVariant() { QVariant v; QCOMPARE(v.toString(), ""); QCOMPARE(v.isNull(), true); QCOMPARE(v.isValid(), false); v.setValue(validDate); QCOMPARE(v.toString(), "2024-05-06"); QCOMPARE(v.isNull(), false); QCOMPARE(v.isValid(), true); } void storeDataInValidVariant() { #if QT_VERSION_MAJOR >= 6 QVariant v(QMetaType::fromType<QDate>()); // Same result if we use the deprecated QVariant(QVariant::Date) constructor in Qt 6 #else QVariant v(QVariant::Date); #endif QCOMPARE(v.toString(), ""); QCOMPARE(v.isNull(), true); QCOMPARE(v.isValid(), true); v.setValue(validDate); QCOMPARE(v.toString(), "2024-05-06"); QCOMPARE(v.isNull(), false); // ERROR: This should definitely be non-null! QCOMPARE(v.isValid(), true); } }; QTEST_MAIN(VariantNullTest) #include "variantnulltest.moc"
Expected outcomes (Qt 5.15)
Full pass
Actual outcomes (Qt 6.x)
storeDataInValidVariant() fails because v.isNull() returns true even though v.toString() returns a non-empty string
********* Start testing of VariantNullTest ********* Config: Using QtTest library 6.7.0, Qt 6.7.0 (x86_64-little_endian-llp64 shared (dynamic) debug build; by MSVC 2019), windows 10 PASS : VariantNullTest::initTestCase() PASS : VariantNullTest::initialiazeDataByConstructor() PASS : VariantNullTest::initialiazeDataFromValue() PASS : VariantNullTest::initializeDataFromType() PASS : VariantNullTest::storeDataInInvalidVariant() FAIL! : VariantNullTest::storeDataInValidVariant() Compared values are not the same Actual (v.isNull()): 1 Expected (false) : 0 ..\..\variantnulltest.cpp(61) : failure location PASS : VariantNullTest::cleanupTestCase() Totals: 6 passed, 1 failed, 0 skipped, 0 blacklisted, 12ms ********* Finished testing of VariantNullTest *********