Reputation: 23
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:
Upvotes: 2
Views: 529
Reputation: 43
remove frontend/
from <file>frontend/*.qml</file>
and add it to <qresource prefix="/">
like this:
<RCC>
<qresource prefix="/frontend/">
<file>main.qml</file>
<file>Home.qml</file>
<file>Home.js</file>
<file alias="qtquickcontrols2.conf">qtquickcontrols2.conf</file>
<file alias="icons/send40x40.png">icons/send40x40.png</file>
<file>AlphaQ/Styles/Style1.0.qml</file>
<file>AlphaQ/Themes/Themes1.0.qml</file>
<file>AlphaQ/Themes/qmldir</file>
<file>AlphaQ/Styles/qmldir</file>
</qresource>
Or if you can move your qml.qrc
to fontend
directory
and add
engine.addImportPath( ":/" );
to your main.cpp
Upvotes: 0