Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-122814

[Reg 6.5.1->6.5.3] Regression in formatting for implicit type conversion from QDateTime to QML string



    • All


      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:

      1. Qt 6.5.1:
        qml: dateTime:Wed Feb 28 14:35:12 2024 GMT+0100
        valid? true
      1. 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)


        1. datetime_to_string_regression.tar.gz
          1 kB
        2. qt651.png
          15 kB
        3. qt653.png
          16 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            ulherman Ulf Hermann
            andrhans Andreas Aardal Hanssen
            0 Vote for this issue
            3 Start watching this issue



              Gerrit Reviews

                There are no open Gerrit changes