I read on the Qt forums that QFile::exists
can be used to test for existence of an image resource.
In my project I have a lot of images, one of the references in a QML file is to:
qrc:/images/ImageViewer/viewer_camera_rear2_off.png
I've checked in Qt Creator and the resource is present and correct, I have added a function to the C++ called checkImage:
QString Manager::checkPath(QString path) {
bool valid = false;
if ( path.length() > 0 && path.indexOf(".") > 0 ) {
const QString QRCprefix("qrc:");
if ( path.startsWith(QRCprefix) != true ) {
const QString imgsPath("/images/");
if ( path.startsWith(imgsPath) != true ) {
path = imgsPath + path; /*Thank you @WilliamMiller*/
}
path = QRCprefix + path;
}
valid = QFile::exists(path);
}
return (valid == true) ? path : "";
}
I've debugged this in Qt Creator and QFile::exists
returns false, I know for an absolute fact that the image and reference is correct and exists, so is the information on the Qt developers forum wrong?
I've also tried changing the QRC prefix to:
qrc:/
qrc://
Result is still the same QFile::exists returns false.