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

QML: string value assignment to C++ QDateTime property behaviour change in Qt6

    XMLWordPrintable

Details

    Description

      Perhaps related to QTBUG-87610, I found something interesting while fixing QtPIM unit tests to work with Qt6 - in this case, Qt6 behaviour is correct, while the previous Qt5 behaviour was incorrect, so I suggest adding a note to the "Porting From Qt5 to Qt6" documentation about this.

      Consider the following main.qml:

      import QtQuick 2.0
      import Helper 1.0
      
      Rectangle {
          width: 200
          height: 200
          color: "lightsteelblue"
          property var helper: Helper { startDateTime: '2011-10-23T15:00:00Z' }
          Component.onCompleted: { console.log("Have startDateTime: " + helper.startDateTime) }
      }
      

      with the following main.cpp:

      #include <QtCore/QCoreApplication>
      #include <QtCore/QVariantMap>
      #include <QtCore/QDateTime>
      #include <QtCore/QString>
      #include <QtCore/QStringList>
      #include <QtCore/QTimer>
      #include <QtCore/QObject>
      
      #include <QtGui/QGuiApplication>
      #include <QtQml/QQmlEngine>
      #include <QtQml/QQmlComponent>
      #include <QtQml/QQmlContext>
      #include <QtQuick/QQuickView>
      
      #include <QtDebug>
      
      class Helper : public QObject
      {
          Q_OBJECT
          Q_PROPERTY(QDateTime startDateTime READ startDateTime WRITE setStartDateTime NOTIFY startDateTimeChanged)
      
      public:
          Helper(QObject *parent = 0) : QObject(parent) {}
      
          QDateTime startDateTime() const { return m_startDateTime; }
          void setStartDateTime(const QDateTime &sdt) { m_startDateTime = sdt; emit startDateTimeChanged(); }
      
      Q_SIGNALS:
          void startDateTimeChanged();
      
      private:
          QDateTime m_startDateTime;
      };
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
      
          qmlRegisterType<Helper>("Helper", 1, 0, "Helper");
      
          QQuickView view;
          view.setSource(QUrl(QStringLiteral("main.qml")));
          view.show();
      
          return app.exec();
      }
      
      #include "main.moc"
      

      Running in machine with locale set to my local timezone (Brisbane, GMT+10).

      With Qt5:

      $ ./testdate
      qml: Have startDateTime: Sun Oct 23 15:00:00 2011 GMT+1000

      With Qt6:

      $ ./testdate
      qml: Have startDateTime: Mon Oct 24 01:00:00 2011 GMT+1000

      It appears that the timezone information is ignored in Qt5, while being correctly handled now in Qt6.  I suggest that this behaviour change be added to the documentation, if it has not been already (and if it has already, I apologise for the noise).

       (It also reproduces similarly for a value like '2011-10-23T15:00:00+0300'.)

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtqmlteam Qt Qml Team User
            chrisadams Christopher Adams
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes