How to set the the path of images in qml file if the qml file is in resource ?
-
wrote on 23 Jun 2011, 03:29 last edited by
but if we embeded the qml files into the qrc files , while the images files is not embeded in the qrc files , like
qml refering using “qrc:/qml/myqml.qml” , images using “images/hello.png”, and images folder is under exe folder , it can’t find the image files .why I want to do it in this way , because I want to hide the qml files when I release my software , while I exposed the images files , because I want to provide skin options , customers can download new images from our website and replace the old image files , how can I solve this problem ? -
wrote on 23 Jun 2011, 06:59 last edited by
You always can pass absolute path of your app folder (which you can retrieve in run-time) as context property to qml and concat it with your image path
-
wrote on 23 Jun 2011, 08:36 last edited by
If do not use an absolute path, Qt makes it relative to the surrounding QML code. And as this is in a resource, it searches for the image in the resources too.
-
wrote on 23 Jun 2011, 09:11 last edited by
thanks , Denis and Volker , you are right , now I can solve this with Denis's suggestion , thanks all of you guys .
-
wrote on 23 Jun 2011, 09:12 last edited by
Volker, OP asks about using non-resourced images in resourced qml. I'm not sure it is possible with relative paths.
-
wrote on 23 Jun 2011, 12:04 last edited by
agree with denis , maybe there is some function which can set the path of the images files , or some
protocol , like "relative:///" -
wrote on 23 Jun 2011, 16:56 last edited by
Relative paths rely on the "parent" path to be resolved. Basically it's an URL. You cannot use relative paths and switch the protocol (from qrc: to file:).
-
wrote on 1 Jul 2011, 03:15 last edited by
thanks , Volker
-
wrote on 17 Jul 2011, 18:56 last edited by
Did you get this to work, for me it just says "QML Image: Protocol "C" is unknown"
But it works with:
source: "file:images/image.jpg"
-
wrote on 18 Jul 2011, 03:10 last edited by
yes , now it works , you can use
@
QString imagePath = QDir::currentPath()+"/images/";
#if defined(Q_OS_MAC)
imagePath = "file://"+imagePath;
#endif
QDeclarativeContext::setContextProperty("imagePath",imagePath);
@ -
wrote on 2 Nov 2012, 05:50 last edited by
Also you can build this and use imagePath hack in Qt Creator and QmlViewer - https://github.com/misterion/QmlViewerDevHelper
-
Please read the following "thread":http://developer.qt.nokia.com/forums/viewthread/5617 because I believe it discuss the same issue.
wrote on 25 Nov 2015, 19:04 last edited by@leon.anavi the link is no longer valid!