[Solved] QDeclarativeView::setSource not working?
I'm using the 4.7 beta 2 on Windows and I'm having trouble getting one of the tutorials to work. It's the one about creating QML types with C++. Basically, I try to run it and when it gets to QDeclarativeView::setSource, it gives the following error:
@<Unknown File>: File error for URL file:app.qml@
setSource is called like so:
and 'app.qml' is definitely present in the same directory as all of the other files in the project - but is not mentioned in the MMP file (should it be?)
Hmm, it seems that using an absolute path works - I guess this might be a bug? Surely it should lookup a qml file the same as it does an image?
DenisKormalev last edited by
try to put your qml file near binary file and try relative path.
So how would I do that in Windows? When building the project, how do I 'export' the QML file to the same location as the binary?
aalpert last edited by
An easier solution is to put the QML file into the binary using Qt's resource system. Then you can access it as ":/app.qml" and don't have to worry about placement of the file.
If app.qml references other QML files, they will also need to be compiled in as resources, and with the same relative path as they have now.
Thanks! That totally works :)
jdbastardy last edited by
[quote author="aalpert" date="1282786194"]
If app.qml references other QML files, they will also need to be compiled in as resources, and with the same relative path as they have now.[/quote]
Just what I needed to know. Thank you!
peter last edited by
with QT 4.7 beta 2: I used a Declarative View to embed a QML GUI in the C++ application - which was working OK. After I installed QT 4.7 Release 2010.05 I have the following problem (I did not change the code):
QDeclarativeComponent: Component is not ready
(<Unknown File>: File error for URL file:///C:/Users/home/git/linuxapp/src/bin/:/qml/gui.qml)
It is part of the resources and was working with 4.7 beta 2:
QDeclarativeComponent component(_engine, QUrl::fromLocalFile(":/qml/gui.qml"));
Now it tries somehow to load the qml-file directly from the working directory. If I change it to:
QDeclarativeComponent component(_engine, QUrl::fromLocalFile("gui.qml"));
it works if I place the qml-file there - but I need to have it in the binary application as a ressource - not in a separate qml file.
Did anybody experience the same problems? How can I make QT 4.7 2010.05 using my ressource file? Tried it on LINUX with cmake and also on Windows using the creator 2.0.1.
peter last edited by
tried it with:
QDeclarativeComponent component(_engine, QUrl("qrc:/qml/gui.qml"));
this works ;-)
Shaci last edited by
peter, thanks for your post! :)
frankiefrank last edited by
I thought this didn't apply to me because I wasn't using resources, but this (using QUrl) in fact did the trick! Thank you!