How to display image in directory?
-
Hi I am quite new to qt. I wrote a program which display image in label. But at first I put image in build folder of my program. It can display fine. But when I move my image to home folder, it cannot display. My image is at Home folder. I am using ubuntu 11.10. my program is like that
@
#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QLabel>int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QImage myImage;
myImage.load(":/Home/1.jpeg");QLabel myLabel; myLabel.setPixmap(QPixmap::fromImage(myImage)); myLabel.show(); return a.exec();
}
@If anything wrong, pls kindly tell me. Thanks.
Edit: please enclose code snippets in @ tags; Andre
-
Hello
I know this was solved, but you could avoid future problems with images when using "Qt's resources mechanism":http://qt-project.org/doc/qt-4.8/resources.html.
bq. The Qt resource system is a platform-independent mechanism for storing binary files in the application's executable. This is useful if your application always needs a certain set of files (icons, translation files, etc.) and you don't want to run the risk of losing the files.
Hope this helps a little bit more and takes you one step further :)
Regards