I'm facing the issue of "module is not installed" when trying to import a new custom QML module to project. I have tried many solutions from the internet and ChatGPT, but I haven't found any correct answer for my case.
This is my project structure.
<ProjectRoot>
|-- frontend/
|-- AlphaQ/
|-- Styles/
|-- Style1.0.qml
|-- qmldir
|-- Themes/
|-- Themes1.0.qml
|-- qmldir
|-- main.qml
|-- Home.qml
|-- Home.js
|-- qtquickcontrols2.conf
|-- src/
|-- main.cpp
|-- qml.qrc
qml.qrc's content:
<RCC>
<qresource prefix="/">
<file>frontend/main.qml</file>
<file>frontend/Home.qml</file>
<file>frontend/Home.js</file>
<file alias="qtquickcontrols2.conf">frontend/qtquickcontrols2.conf</file>
<file alias="icons/send40x40.png">frontend/icons/send40x40.png</file>
<file>frontend/AlphaQ/Styles/Style1.0.qml</file>
<file>frontend/AlphaQ/Themes/Themes1.0.qml</file>
<file>frontend/AlphaQ/Themes/qmldir</file>
<file>frontend/AlphaQ/Styles/qmldir</file>
</qresource>
</RCC>
frontend/AlphaQ/Styles/Style1.0.qml:
module AlphaQ.Styles
singleton Style 1.0 Style1.0.qml
frontend/AlphaQ/Themes/Themes1.0.qml:
module AlphaQ.Themes
singleton Themes 1.0 Themes1.0.qml
main.qml
import QtQuick 2.15
import QtQuick.Window 2.15
import AlphaQ.Styles 1.0
The problem can be solved by call this command inside main.cpp:
qmlRegisterSingletonType(QUrl("qrc:/frontend/AlphaQ/Styles/Style1.0.qml"), "AlphaQ.Styles", 1, 0, "StyleA");
But I'm expect the solution from qmldir, please help me find out what's wrong. Thanks
This list is what I have tried:
- engine.addImportPath
- set prefix AlphaQ.Styles in QRC
- qmlRegisterSingletonType ( This fix my issue, but I expect other solutions)
- set QML_IMPORT_PATH = $$PWD\frontend\
remove
frontend/
from<file>frontend/*.qml</file>
and add it to<qresource prefix="/">
like this:
Or if you can move your
qml.qrc
tofontend
directory and addto your
main.cpp