PDA

View Full Version : Problem with ressource file



cpper
25th July 2016, 16:02
Hello :)
I'm having trouble adding images in qt projects, through qrc files. I'm trying to add an image to a label, but can't do it. I click on "Copy path", paste it in the code, but when running the label remains blank. I tried adding an additional '/' but it's not working. If I enter the absolute path(C:\User...) I can see the image.

Here a screenshot: http://i.imgur.com/8JoRQYZ.png

anda_skoa
25th July 2016, 16:28
Check if the file is actually in the resource system.

E.g. use QDir to list ":/" or use the resource inspector in GammaRay https://www.kdab.com/gammaray/

Btw, QLabel can scale its contents to its size, but if you want to scale yourself, load into a QImage and convert the result of it scaling function to QPixmap.
This is more efficient, since QPixmap scaling needs to convert to QImage anyway.

Cheers,
_

cpper
25th July 2016, 16:58
Thanks for the reply. Could you please provide the code for checking if the file is in the ressource system via QDir ? I'm a complete beginner and am having a hard time.

anda_skoa
25th July 2016, 17:27
foreach (const QString &file, QDir(":/").entryList()) {
qDebug() << file;
}


Cheers,
_

cpper
25th July 2016, 17:57
I wrote the same code in a new project and could see the image. Strange.

d_stranz
25th July 2016, 23:05
Most likely -wasn't- "the same code", and if it was, then most likely you hadn't put your image files into the Qt resources for your program correctly. Compilers don't generally take "the same code" and produce different results each time through.