Maybe the file you are loading is missing as a resource defined in your .qrc
Maybe the file you are loading is missing as a resource defined in your .qrc
yeah, i was thinking the same thing. but then again, why would the source be wrong if i used the build in browser... and why should the preview know where to find it but not the code.... dosn t make much sense.. does it?... mmmm..... maybe i should put some code in just to make things a little clearer..
Qt Code:
#include <QApplication> #include <QLabel> int main(int argc, char *argv[]) { label->show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
so now what i did is... i wrote this little code only to show the pic. and the line with the setPixmap i just took out of the file which was createt by the desiner..... what happens when i run it on my mashine is... i m seeing just the grey background of the mainwindow.. and not the picture..... which i did put in the directory of the project....
I dont think that setting file in the designer will add it as a resource. I think it just sets a property. Please correct me if I am wrong
So, either the file is external and need to be found at execution, etiher it is embedded as a resource. In that last approach, you can add it in your .qrc first, then get access to it by prefixing name with ":" and a resource prefix like that ":/prefixInQrc/pathTotheFile"
Anyway, you can check if file exists while QFileInfo::exists and if pixmap has been loaded with QPixmap::isNull or return value of QPixmap::load
hi,
i tried the approach using the qt resource system u mentioned and it worked instantly. oh yeah, i also gave the isnull fn a try... also very useful...
so thx a million 4 ur help
oh well yeah.. if someone else is ever going to have the same problem.... this way u can display the pic...
Qt Code:
#include <QApplication> #include <QLabel> #include <QPixmap> int main(int argc, char *argv[]) { label->setPixmap(image); if(image.isNull()){ label->setText("null pic"); } label->show(); return app.exec(); }To copy to clipboard, switch view to plain text mode
but u need to create a resource file and mention there ur picture.... in my case... bild.bmp... oh yeah.... and also u need to mention ur resource file in your project file... sounds really more depressing than it is.... if u use qt creator.... things are even done for u... just create a new res file... and select there the stuff u want to have.... then u can just use it the :/ way shown in the code... the rest ll be done for u...
enjoy
Not to stay passive, I've decided to link my executable with debug versions of Qt libs.
I hope discovering why image loading is unsuccessful.
I keep informed the forum.
Thank you all for your suggestions. It permits at least to eliminate tracks and to discriminate the causes.
Bookmarks