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

QML_ELEMENT does not work as expected with precompiled_headers

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • Some future release
    • 6.5.3
    • QML: Tooling
    • None
    • Windows

    Description

      To declare a QML element from C++, one can use QML_ELEMENT with qt_add_qml_module, and it works nicely... until you add precompiled_headers to the mix.

      See attached project, the precompiled_headers contains QQmlEngine, and the TestItem is declared as is:

      #ifndef TESTITEM_H
      #define TESTITEM_H
      
      #include <QObject>
      
      class TestItem : public QObject{
          Q_OBJECT
          QML_ELEMENT
      public:
          explicit TestItem(QObject *parent = nullptr);
      };
      #endif // TESTITEM_H 

      As you can see, QQmlEngine is not included here, and everything compiles fine thanks to precompiled_headers.

      But when running, you got this error:

      qrc:/qt/qml/test_bug/Main.qml:11:5: TestItem is not a type 

      TestItem is not in the module... adding the include QQmlEngine fixes it.

       

      As long as the code compile, the QML_ELEMENT tag should be handled properly, even without the QQmlEngine inc;ude.

      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
            narnaud Nicolas Arnaud-Cormos
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes