Mixing qrc and local QML files
-
Hi,
I have 3 QML files:
@
// ComponentA.qml
import QtQuick 2.0Item {
ComponentB {}
}
@
@
// ComponentB.qml
import QtQuick 2.0Item {
ComponentC {}
}
@
@
// ComponentC.qml
import QtQuick 2.0Item {}
@ComponentA and ComponentC are in the qrc. ComponentB should be left in a local directory to be edited by a user.
@
<RCC>
<qresource prefix="/">
<file>ComponentA.qml</file>
<file>ComponentC.qml</file>
</qresource>
</RCC>
@Loading ComponentA logically causes an error because the QML engine can't find ComponentB in the ressource system.
@engine.load(QUrl(QStringLiteral("qrc:/ComponentA.qml")));@
@qrc:/ComponentA.qml:5 ComponentB is not a type@Is there any way to make the QML engine look for files in a specific local directory if they are not found in the ressource system?
-
Hi and Welcome to Qt Devnet,
Since the first file that you are loading is in Resource System, further files will also be searched in Resource. The best way would be to use a "Loader":http://doc.qt.io/qt-5/qml-qtquick-loader.html Item to load the external file. For eg:
@
import QtQuick 2.4
Item {
Loader {
source: "file:///home/as/ComponentB.qml"
}
}
@ -
Works for ComponentB. But now ComponentC needs to be loaded by a Loader to get back to the resource system.
@
import QtQuick 2.4
Item {
Loader {
source: "qrc:///ComponentC.qml"
}
}
@Is there any more convenient way to let the engine handle the switching between ressources and local files automatically?
-
bq. But now ComponentC needs to be loaded by a Loader to get back to the resource system.
The above code should work.
bq. Is there any more convenient way to let the engine handle the switching between ressources and local files automatically ?
I haven't come across any other way. May be "setBaseUrl()":http://doc.qt.io/qt-5/qqmlengine.html#setBaseUrl, but not sure though.
-
Hi,
I've just posted on a similar thread, how it is possible to mix qrc and non-qrc files with "V-Play":http://v-play.net...
You can find the forum thread "here":http://qt-project.org/forums/viewthread/52478/P15/#217901.Cheers, Chris