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

No specific warning when trying to expose a C++ type to QML which has no default constructor

XMLWordPrintable

      I had a type which I had copied from elsewhere and had forgotten to remove its constructor:

          class ComponentCreator : public QObject
          {
              Q_OBJECT
              QML_ELEMENT
              QML_SINGLETON
              Q_MOC_INCLUDE(<QtQml/qqmlcomponent.h>)
      
          public:
              ComponentCreator(QQmlEngine *engine);
      
              Q_INVOKABLE QQmlComponent *createComponent(const QByteArray &data);
          };
      

      Attemping to use this in QML resulted in a vague warning:

      QWARN  : tst_controls::Basic::StackView::test_componentCreatedFromCpp() file:///home/mitch/dev/qt-dev/qtdeclarative/tests/auto/quickcontrols2/controls/data/tst_stackview.qml:1555: TypeError: Cannot call method 'createComponent' of undefined
      

      It would be easier for users to understand what was going wrong if there was a specific error message. For example:

      "ComponentCreator cannot be exposed to QML because it has no default constructor."
      

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

            qtqmlteam Qt Qml Team User
            mitch_curtis Mitch Curtis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes