How to set the the path of images in qml file if the qml file is in resource ?
-
thanks , Denis and Volker , you are right , now I can solve this with Denis's suggestion , thanks all of you guys .
-
Volker, OP asks about using non-resourced images in resourced qml. I'm not sure it is possible with relative paths.
-
agree with denis , maybe there is some function which can set the path of the images files , or some
protocol , like "relative:///" -
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:).
-
thanks , Volker
-
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"
-
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);
@ -
Also you can build this and use imagePath hack in Qt Creator and QmlViewer - https://github.com/misterion/QmlViewerDevHelper
-
@leon.anavi the link is no longer valid!
-
This is really informative.