Friday 15 May 2015

qt - QLabel doesnot display image when run from QtCreator -


When I run the program with Qt Creator 2.7.0, a blank application window appears. It works when I run executable in the release folder What can be the problem?

  int main (int argc, char * argv []) {Q application application (argc, argv); Qualabal Top Level Labels; QPixmap pixmap ("gem.jpg"); TopLevelLabel.setPixmap (Pixmap); TopLevelLabel.setMask (pixmap.mask ()); TopLevelLabel.show (); Return app.exec (); It seems that your pixmap has failed to load because the image file can not be found    

You should check it using the pixmap.isNull () before using it.

It is better to keep the image file in the QT resource file, so it will be included in the executable file.

If you still want to load the file that is stored in the same directory as executable, note that "gem.jpg" is relative to the work directory. The path is there. You need to code your code to QApplication :: arguments (). Need to use (0) on and construct the full path of the image. However, note that QT producers usually generate executables in a temporary build directory, so you need to copy your image file into it.

OK, like I said, it is better to put the image file in the QT resource file

No comments:

Post a Comment