1
votes

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?

2
Why are you using the application viewer? Does it work without using that? Show your project file, please. - lpapp
You can set QML_IMPORT_TRACE to get more detailed information what gets loaded. - Sebastian Dressler
@LaszloPapp Actually I'm using the default template generated by QtCreator when I asked to create a Quick app, what this viewer means? - dfranca
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! - dfranca

2 Answers

1
votes

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
0
votes

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!