Problem in interaction and accessing files between the resource in the static library from application.
-
I have created a static lib which has two resource files images.qrc and libResource.qrc.
libResource.qrc has the TestQtQml.qml file and images.qrc file has the test1.png .
test1.png is accessed and displayed in the TestQtQml.qml(present in libResource.qrc) file as below.
TestQtQml.qml import QtQuick.Window 2.12 Item { visible: true width: 640 height: 480 // title: qsTr("TextInput Element Demo") Image { width: 130; height: 100 source: "qrc:/images/test1.png" } }
TestQtQml.qml file is accessed in the main.cpp by using the api
Q_INIT_RESOURCE(libResource);But TestQtQml.qml file is not able to find the test1.png within the static library when both are files are placed as two different resources.
Please let us know can we use multiple resources within the static library or all the files should be embedded within a single resource file?
Note:
(when both TestQtQml.qml and test1.png are embedded within the single resource file, TestQtQml.qml file is able to access the test1.png)main.cpp #include "mainwindow.h" #include <QApplication> #include <QFile> #include <QDebug> #include <QQmlEngine> #include <QQmlComponent> #include <QQuickView> #include <QQmlApplicationEngine> #include <QQuickItem> #include <QObject> int main(int argc, char *argv[]) { Q_INIT_RESOURCE(libResource); Q_INIT_RESOURCE(images); QApplication a(argc, argv); QQuickView view; view.setSource(QUrl::fromLocalFile(":/TestQtQml.qml")); view.show(); return a.exec(); }
-
Hi,
As shown in the documentation, you should first create the QApplication object.
-
We have tried initialising QApplication object first.Still TestQtQml.qml file is not able to access test1.png.
main.cpp #include "mainwindow.h" #include <QApplication> #include <QFile> #include <QDebug> #include <QQmlEngine> #include <QQmlComponent> #include <QQuickView> #include <QQmlApplicationEngine> #include <QQuickItem> #include <QObject> #include "acessqrc.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); Q_INIT_RESOURCE(libResource); Q_INIT_RESOURCE(images); QQuickView view; view.setSource(QUrl::fromLocalFile(":/TestQtQml.qml")); view.show(); view.rootObject()->setProperty("myloaderSource","qrc:/qml/TestItem.qml"); QObject *testobject = view.rootObject(); return a.exec(); }
-
Try setting a different prefix for the resources you are using.
-
Thanks. issue is resolved after changing the prefix.
-
You're welcome !
Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :-)