Question

I did an app loading qml from local filesystem, and it was working fine, but now I'm trying to change it to load from qml, but it never find my file.

I've looked into the web and tried some solutions, nothing worked.

My qml file is in a subdirectory of the project qml/MyProject/main.qml Then I created a resource file and added a prefix "/" (tried with different names too), and then added my qml file to it.

Then I changed the generated qtquick2applicationviewer.cpp setMainQmlFile to: http://pastebin.com/kRJDJACW

Then I tried the following lines to load the qml from resource:

viewer.setMainQmlFile("qrc:/main.qml");
viewer.setMainQmlFile("qrc://main.qml");
viewer.setMainQmlFile("qrc:/other_prefix/main.qml");
viewer.setMainQmlFile("qrc:/qml/MyProject/main.qml");
viewer.setMainQmlFile("qrc://qml/MyProject/main.qml");

My resource file: http://pastebin.com/1sjUqk2T

Qt version: 5.2/ QtCreator 3.0

What am I doing wong?

Was it helpful?

Solution

The code you are showing looks alright, at least the following line:

viewer.setMainQmlFile("qrc:/main.qml");

The error is likely somewhere else. You have not shared the project file of yours, but the reason is probably that you do not have this file correctly in your resource.

You would need to use the following entry in your qmake file:

RESOURCES = main.qrc

OTHER TIPS

Solved, thanks guys. For some reason my resource file was in "other files", not in "resources" area of Qt Creator, so I added a new one and it worked. Thanks!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top