Unsolved path for image Label
-
Hello,
I need to tp image Label
If I use
QPixmap pix("E:/work/QTProgz/logo.jpg");
ui->imagelabel->setPixmap(pix);
ui->imagelabel->setScaledContents(true);It's showing
But if i dont know directoryQString imageFileName;
imageFileName=(QDir::currentPath()).append("/logo.jpg");
QPixmap pix(imageFileName);
ui->imagelabel->setPixmap(pix);
ui->imagelabel->setScaledContents(true);it's not showing
So how to fix it ?
Thanks
-
Hi
The best way to fix is to use resource.
as absolute path will break as soon it sees a new pc.
http://doc.qt.io/qt-5/resources.htmlhttp://www.bogotobogo.com/Qt/Qt5_Resource_Files.php
ps no need to add Add Prefix. -
Thank you for your reply
but i'm working under Qt 4.7
I'm not sure that it supports resources
-
@Vics
The menus are not there in Creator ? -
There are no resources in menus in Creator
I havent anything like showing there http://www.bogotobogo.com/Qt/Qt5_Resource_Files.phpP.S. my logo jpg file holds in the same dir, where holds the application.
-
Hi,
The Qt resource system has been there way before Qt 4.7.
You may have to write the file by hand but it's not that hard. See here.