I'm merging two QML\Qt project into new one and I've a problem with *.qml files. In original projects I've a main.qml with timer, proprieties,... and a loader for bring-up the custon *.qml, to summarize: 2 folder (QML_10 and QML_15), 2 main.qml and several other qml files. I would have a sinle project which is able to load one main or other in according to arcv[] C parameter. in my C code :
QUrl url(QStringLiteral("qrc:/main.qml"));
if (atoi(argv[1]) == ROLE1)
url.setUrl(QString("/QML_10/main.qml"))
else if (atoi(argv[1]) == ROLE2)
url.setUrl(QString("/QML_15/main.qml"))
else
printf("Error\n")
When I run the application I'm able to detect the right role but the setYrl doesn't work with error :
file:///QML_1/main.qml: No such file or directory
CodePudding user response:
With setUrl
you replace the complete content of QUrl, leading to a URL without scheme, upon which the default file:
scheme is assumed. You should either put qrc:
in front, or use setPath
.
Alternatively you could use setScheme("qrc")
afterwards.