Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. "QML_ELEMENT does not name a type" in Qt 5.15

"QML_ELEMENT does not name a type" in Qt 5.15

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5.15
8 Posts 5 Posters 7.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    freeheeler
    wrote on 26 May 2020, 16:03 last edited by
    #1

    Hi,

    I just installed Qt 5.15 and wanted to try some of the new features, starting with the new QML type registration macro. Following the documentation here, I added the following to my .pro:

    CONFIG += qmltypes
    QML_IMPORT_NAME = org.example.ufcs
    QML_IMPORT_MAJOR_VERSION = 1
    

    And I added QML_ELEMENT to a class I wanted to register:

    class PCHelper : public QObject
    {
        Q_OBJECT
        QML_ELEMENT
    
        Q_PROPERTY(double setPoint MEMBER mSetPoint NOTIFY setPointChanged)
        ...
    }
    

    I made sure to use the new Qt version (and not 5.14.2 which is also installed), but I still get the error:
    'QML_ELEMENT' does not name a type.

    Also, when I run qmake, I get this warning:
    Warning: Failure to find: ufcs-pc_metatypes.json

    What did I miss?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      FKosmale
      wrote on 26 May 2020, 19:19 last edited by
      #2

      Did you include <qqml.h>? That's where QML_ELEMENT is defined.

      About the qmake warning: That's IIRC an open bug; but the warning is harmless. The json file should be generated once you run make/nmake.

      1 Reply Last reply
      1
      • F Offline
        F Offline
        freeheeler
        wrote on 27 May 2020, 17:06 last edited by freeheeler
        #3

        Thank you, including <qqml.h> solved that error.
        However, another error appeared:

        [...]/ufcs/build-ufcs-pc-Desktop-Qt5.15-Debug/ufcs-pc_qmltyperegistrations.cpp:10: error: guihelper.h: No such file or directory
         #include <guihelper.h>
                  ^~~~~~~~~~~~~
        

        (guihelper.h is the file where I define the class that has the QML_ELEMENT macro)

        I was able to solve this by adding my source folder to the .pro file:

         INCLUDEPATH += src/cpp
        

        It's a little counter-intuitive since I've never needed to add this before to get a Qt project to build but hey, it works.

        Thanks for your help!

        EDIT: actually despite the build succeeding, this didn't work. I hadn't realized I'd left the qmlRegisterType line in main.cpp. If I remove that, the application doesn't open, with a QML error saying that the type does not exist.

        Isn't the QML_ELEMENT macro supposed to replace the qmlRegisterType instruction? Is there anything else that I need to make this work? The documentation doesn't mention anything else as far as I can tell.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jay1
          wrote on 27 May 2020, 19:26 last edited by jay1
          #4

          Did you use "import org.example.ufcs 1.0" in the qml file that you have used ?

          F 1 Reply Last reply 27 May 2020, 20:39
          0
          • J jay1
            27 May 2020, 19:26

            Did you use "import org.example.ufcs 1.0" in the qml file that you have used ?

            F Offline
            F Offline
            freeheeler
            wrote on 27 May 2020, 20:39 last edited by
            #5

            @jay1 Yes I did. Sorry, I should've included that in my previous post.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              freeheeler
              wrote on 29 May 2020, 15:20 last edited by
              #6

              I think I've solved it. The problem was that I had a mix of methods for exposing C++ parts of the project to QML.
              Specifically, I still had some qmlRegisterType lines in my main.cpp that used the same import name as the one I defined in the .pro. I guess this caused some kind of conflict that resulted in the class with the QML_ELEMENT macro not to be found by the QML side of things.

              So, changing the QML_IMPORT_NAME to something unique (and including that new name in the QML file) solves this problem.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                parul1987
                wrote on 24 Jun 2020, 17:18 last edited by parul1987
                #7

                I am also getting the same issue . can u plzz share your code

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Chaba
                  wrote on 8 Jun 2021, 12:18 last edited by
                  #8

                  I tried to build OpenGL Under QML example (https://doc.qt.io/qt-5/qtquick-scenegraph-openglunderqml-example.html). I get same error with version 5.14.1, but it works fine with version 5.15.2.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved