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

QQuickItem::classBegin()/componentComplete() never invoked when using QQmlComponent::loadFromModule()

    XMLWordPrintable

Details

    • Windows
    • 8896d380a (dev), 40cde2552 (6.7), 0e4d4d4a4 (6.6), 385436f2a (tqtc/lts-6.5)

    Description

      #pragma once
      
      #include <QtQuick/QQuickItem>
      
      class CppItem : public QQuickItem {
          Q_OBJECT
          QML_ELEMENT
          Q_PROPERTY(QString text MEMBER text)
      private:
          QString text;
          auto componentComplete() -> void final
          {
              QQuickItem::componentComplete();
              qDebug() << "componentComplete" << text;
          }
      };
      
      #include <QtQuick>
      #include "cppitem.hpp"
      
      int main(int argc, char **argv) {
      
          QGuiApplication app(argc, argv);
      
          QQuickWindow window;
          QQmlEngine engine;
      
          {
              QQmlComponent component{&engine};
              component.setData("import App; CppItem {}", {});
              component.createWithInitialProperties(QVariantMap{{"text", "load from data"}});
          }
          {
              QQmlComponent component{&engine};
              component.loadFromModule("App", "CppItem");
              component.createWithInitialProperties(QVariantMap{{"text", "load from module"}});
          }
      
          return 0;
      }
      

      Here, same type QML item CppItem created twice, first one is using QQmlComponent::setData() and second one is using QQmlComponent::loadFromModule().
      Here's the result:

      19:47:01: Starting path\app.exe...
      QML debugging is enabled. Only use this in a safe environment.
      componentComplete "load from data"
      19:47:01: path\app.exe exited with code 0
      

      As you can see, componentComplete() is not called for the one created by QQmlComponent::loadFromModule().
      Same for classBegin(), so I think QQmlParserStatus is not working for QQmlComponent::loadFromModule().

      Attachments

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

        Activity

          People

            fabiankosmale Fabian Kosmale
            bylee Byoung-young Lee
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes