Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
None
-
6.3.1
-
None
Description
QVariantMap map = QVariantMap({ { QStringLiteral("data"), QDateTime() } }); qDebug().noquote() << QJsonDocument::fromVariant(map).toJson(QJsonDocument::Compact); QJsonObject jo; jo[QStringLiteral("data")] = QJsonValue::fromVariant(QVariant(QDateTime())); qDebug().noquote() << QJsonDocument(jo).toJson(QJsonDocument::Compact);
A different output when running the code above in Qt5 and Qt6
Output of Qt5 (5.6.0):
{"data":null} {"data":null}
Output of Qt6 (6.3.1), expected output is the same as Qt5 but it not:
{"data":""} {"data":null}
I am having trouble upgrading from Qt5 to Qt6 because this change is breaking my handle.
I have a workaround that checks whenever QDateTime is null(), then inserts QVariant().
QVariantMap map; map.insert(key, date.isNull() ? QVariant() : date);
Is there any other solution for this?
*I have searched but couldn't find any documents or bugs related to this, so I created this ticket. I hope you guys will respond soon. Many thanks.