Unable to load from qrc after "Add new... (QML file)" 🍀
Solved
QML and Qt Quick
-
I created a very basic application (MWE). I'm not able to create my own QML file and subsequently import it into
main.qml
.QMLSide.qml:
import QtQuick 2.12 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.3 Frame { ListView { implicitWidth: 250 implicitHeight: 250 model: 100 delegate: RowLayout { CheckBox {} TextField {} } } }
main.qml:
import QtQuick 2.12 import QtQuick.Controls 2.5 import "QMLSide.qml" ApplicationWindow { visible: true width: 300 height: 120 title: qsTr("Hello World") MyListView { } }
See screenshot for errors but it says:
qrc:/main.qml:3 "QMLSide.qml": no such directory qml\qqmlapplicationengine.cpp: 132
Any ideas how to get it to import properly?
-
@enjoysmath said in Unable to load from qrc after "Add new... (QML file)" 🍀:
Any ideas how to get it to import properly?
Do not import anything, just use it.
QML engine always scans the current directory - all files in the same directory as
main.qml
are automatically available and recognized.You only need to use
import
when your QML code is in a different directory, and you should only specify the directory path, not file path. -
Thanks @sierdzio that was very helpful! :)