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

QML Registration wrong warning

    XMLWordPrintable

Details

    • All
    • 6ea6bbeb3 (dev)

    Description

      When trying to register non default constructible class derived from `QObject` as QML type, there's a warning during the registration: `<CLASS NAME> is neither a QObject, nor default- and copy-constructible, nor uncreatable. You should not use it as a QML type.`

      Example of such class:

       

      class MyObject: public QObject {
          Q_OBJECT
          QML_ELEMENT
      
      public:
          explicit MyObject(int value, QObject* parent = nullptr);
      };

       

      According to the warning message such class should work without any warnings because it's derived from `QObject`.

      I quickly looked at the code and according to this line https://github.com/qt/qtdeclarative/blob/6.5.1/src/qml/qml/qqmlprivate.h#L973 , if a class is not default constructible it does not even check latter conditions.

      Why this is important because according to this comment https://github.com/qt/qtdeclarative/blob/6.5.1/src/qml/qml/qqml.h#L777 , this check will be replaced with static assert which will lead to the code that won't compile at all.

      Is this a misleading warning message or a bad condition, or I misunderstood something?

      Thanks!

      P.S. I did not have such a warning in Qt 6.4.

      Attachments

        For Gerrit Dashboard: QTBUG-114966
        # Subject Branch Project Status CR V

        Activity

          People

            amanda.hamblin-true Amanda Hamblin-True (Inactive)
            farmovit Farmo Vit
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes