Home > Mobile >  QML module is not installed
QML module is not installed

Time:05-27

I want to try import qml file.

And I already try QML_IMPORT_PATH, .qrc, qmldir.

But always got the error: QML module is not installed.

Please where am I missing? I using Qt6.3, MacOS

enter image description here

here is .pro file

QT  = quick

SOURCES  = \
        main.cpp

RESOURCES  = qml.qrc

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH  = $$PWD/Components

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

QT_DEBUG_PLUGINS=1
QML_IMPORT_TRACE=1

INSTALLS  = target

DISTFILES  = Components/qmldir

here is qmldir

Module Components

TestItem 1.0 TestItem.qml

here is qrc

<RCC>
    <qresource prefix="/">
        <file>Components/qmldir</file>
        <file>Components/TestItem.qml</file>
        <file>main.qml</file>
    </qresource>
</RCC>

here is main.qml

import QtQuick
import TestItem 1.0
Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
}

here is TestItem.qml

import QtQuick 2.0

Item {

}

I also push my test code on github https://github.com/OtisLin123/QMLComponentTest

CodePudding user response:

While importing, you should specify the module name, and not the component name:

import Components 1.0 // instead of import TestItem 1.0

This will import all components included in the qmldir.

  • Related