PDA

View Full Version : Can’t load the image after I register the qml file to Qt resource system



stereoMatching
17th June 2013, 04:01
main.qml



import QtQuick 2.0

Rectangle {
width: 360
height: 360

Image{
anchors.fill: parent
source: "/Pictures/img_0000.jpg"
}
}



main.cpp


#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"

int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);

QtQuick2ApplicationViewer viewer;
//viewer.setMainQmlFile(QStringLiteral("qml/qmlResource/main.qml"));
viewer.setSource(QStringLiteral("qrc:///qml/qmlResource/main.qml"));
viewer.showExpanded();

return app.exec();
}



error message

qrc:///qml/qmlResource/main.qml:7:5: QML Image: Cannot open: qrc:///Pictures/img_0000.jpg

looks like the Image complain it can not find the image from qrc
but I don’t want the program to load the image from qrc
it is not my intention

Added after 28 minutes:

Find the answer
http://qt-project.org/forums/viewthread/10477

stereoMatching
28th June 2013, 01:44
just add "file:///" before "/Pictures/img_0000.jpg"
after you register main.qml into qrc list
every image you load will prepend "qrc://" so the program would
assume the image is located inside your binary
prepend "file:///" could tell the program "this file do not reside in the binary"