Details
-
Bug
-
Resolution: Invalid
-
P1: Critical
-
6.5.3
-
None
Description
Regression from Qt 6.5.1 to 6.5.3: The string format for QDateTime when assigned to a string property in QML changed. (See attached isolated example.) Intentional or not, hard to tell, but it did break our application when upgrading.
(Context: QML doesn't allow passing C++ QDateTime through QML property var to a C++ Q_INVOKABLE function with a QDateTime argument: "TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed." So, if a model has a QDateTime type role, and this is used in QML as in the example, and the datetime is passed to C++ again, it must either be a string all the way through, or the Q_INVOKABLE must take a QString argument and parse the string representation of the QDateTime. This is what happened in our application, and that parsing broke (as in the attached example).)
Brief: If a QVariant storing a QDateTime is passed in from C++, and accessed from QML, its conversion to string behavior is different in Qt 6.5.1 and 6.5.3. The attached example, inlined QML below, exposes the QDateTime type as a named role, "dateTime", through a custom model "Model". This model is used in a ListView whose delegate uses a Text to demonstrate the differences in conversion.
The difference lies in what happens when the type is converted on the fly, perhaps through implicit left-to-right type deduction, vs when it's converted when stored in a string property. See screenshots; output when run with the two versions:
- Qt 6.5.1:
qml: dateTime:Wed Feb 28 14:35:12 2024 GMT+0100
dateTimeStr:2024-02-28T14:35:12.456
valid? true
- Qt 6.5.3:
qml: dateTime:Wed Feb 28 14:36:10 2024 GMT+0100
dateTimeStr:Wed Feb 28 14:36:10 2024 GMT+0100
valid? false
ListView { width: 400 height: 100 model: Model { id: testModel } delegate: Text { property string dateTimeStr: dateTime text: "dateTime:" + dateTime + "\ndateTimeStr:" + dateTimeStr + "\nvalid? " + testModel.verifyDate(dateTimeStr) } }