Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

(Qt5.15.0 + Qt Creator 4.12.4) Qml Module not found - Integrating QML and C++



  • Hello, based on the Integrating QML and C++ I made the registration for the C++ Class, but Qt Creator reports the error "Qml Module not found". I made a breakpoint into the C++ Class and executed a Debug session and by Textchange the breakpoint gets hit, means the Module is found.

    How I solve the Error Message, because is annoying and code completion doesn't work

    Operationsystem: Windows 10
    Qt Version: Qt5.15.0
    Qt Creator: 4.12.4
    ompiler: MSVC2019 64Bit

    Pro file:

    QT += quick
    
    CONFIG += c++11
    
    CONFIG += qmltypes
    QML_IMPORT_NAME = io.qt.examples.backend
    QML_IMPORT_MAJOR_VERSION = 1
    
    
    # The following define makes your compiler emit warnings if you use
    # any Qt feature that has been marked deprecated (the exact warnings
    # depend on your compiler). Refer to the documentation for the
    # deprecated API to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
            backend.cpp \
            main.cpp
    
    RESOURCES += qml.qrc
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    HEADERS += \
        backend.h
    

    backend.cpp

    #include "backend.h"
    
    BackEnd::BackEnd(QObject *parent) :
        QObject(parent)
    {
    }
    
    QString BackEnd::userName()
    {
        return m_userName;
    }
    
    void BackEnd::setUserName(const QString &userName)
    {
        if (userName == m_userName)
            return;
    
        m_userName = userName;
        emit userNameChanged();
    }
    

    backend.h:

    #ifndef BACKEND_H
    #define BACKEND_H
    
    #include <QObject>
    #include <QString>
    #include <qqml.h>
    
    class BackEnd : public QObject
    {
        Q_OBJECT
        Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged)
        QML_ELEMENT
    
    public:
        explicit BackEnd(QObject *parent = nullptr);
    
        QString userName();
        void setUserName(const QString &userName);
    
    signals:
        void userNameChanged();
    
    private:
        QString m_userName;
    };
    
    #endif // BACKEND_H
    

    main.qml:

    Line 3 "import io.qt.examples.backend 1.0" I get the error Qml Module not found

    import QtQuick 2.6
    import QtQuick.Controls 2.0
    import io.qt.examples.backend 1.0
    
    ApplicationWindow {
        id: root
        width: 300
        height: 480
        visible: true
    
        BackEnd {
            id: backend
        }
    
        TextField {
            text: backend.userName
            placeholderText: qsTr("User name")
            anchors.centerIn: parent
    
            onTextChanged: backend.userName = text
        }
    }
    

    This file gets generated:

    [
        {
            "classes": [
                {
                    "classInfos": [
                        {
                            "name": "QML.Element",
                            "value": "auto"
                        }
                    ],
                    "className": "BackEnd",
                    "object": true,
                    "properties": [
                        {
                            "constant": false,
                            "designable": true,
                            "final": false,
                            "name": "userName",
                            "notify": "userNameChanged",
                            "read": "userName",
                            "required": false,
                            "scriptable": true,
                            "stored": true,
                            "type": "QString",
                            "user": false,
                            "write": "setUserName"
                        }
                    ],
                    "qualifiedClassName": "BackEnd",
                    "signals": [
                        {
                            "access": "public",
                            "name": "userNameChanged",
                            "returnType": "void"
                        }
                    ],
                    "superClasses": [
                        {
                            "access": "public",
                            "name": "QObject"
                        }
                    ]
                }
            ],
            "inputFile": "backend.h",
            "outputRevision": 67
        }
    ]
    


  • Hello, does somebody can confirm same issue?



  • I am not sure it's the same issue, but I have a similar problem, but in my QML I explicitely use 2.15 module import ("import QtQuick 2.15")

    I can see in QT Creator, menu Help->System information... that QT creator is built against QT 5.14.2, so if I change my QTQuick version to 2.14 in QML import, it works.

    That is, it seems that the import supported version depends from QT Creator QT build version, which is weird. If so, guys, please rebuilt QT Creator always with latest QT version, so 5.15 in this case.


Log in to reply