View Full Version : Image loading
Stanfillirenfro
15th January 2014, 09:57
Hi!
I am trying to get the path top a QImage for my application.
I did as followd:
QPixmap image;
image.load(QCoreApplication::applicationDirPath() + "/Desktop/myImage");
My problem is that I can not load any image.
What could be the problem? I will appreciate any help.
Many thanks in advance.
aamer4yu
15th January 2014, 10:24
Where is the image name ? "myImage.png" , myImage.jpg ?? which one ?
Also what is the output of QCoreApplication::applicationDirPath() ?
Stanfillirenfro
15th January 2014, 10:35
Many thanks aamer4yu for your reply.
The image name should be myImage.png.
Have a look please. When I proceed as followed, I do not need to add ".png", and I can have the image loaded. But I do not want to go this way.
image.load("C:/Users/Desktop/myImage");
Even by writing myImage.png, there is no change.
I have created a label on which th image should appear as followed:
m_image = new QLabel(this);
m_image->setPixmap(myImage);
Lesiok
15th January 2014, 11:11
Are you sure you know what QCoreApplication::applicationDirPath() returns ?
Stanfillirenfro
15th January 2014, 11:21
Thanks Lesiok!
Yes, QCoreApplication::applicationDirPath() returns the directory that contains the application executable.
aamer4yu
15th January 2014, 12:11
Please put a qDebug() for QCoreApplication::applicationDirPath() value...
Stanfillirenfro
15th January 2014, 13:09
Thanks aamer4you for your reply.
I am instead trying to proceed like this:
QDir dir;
dir.setCurrent("C:/Users/File/Desktop/imageFile");
image.load(dir + "/myImage");
This does not function. Could you please have a lokk and give me an advice?
Many thanks in advance.
Added after 41 minutes:
I have solved the problem.
Many thanks for our help.
Lesiok
15th January 2014, 13:11
Can You show us what is FULL path to file myImage and what is result of QCoreApplication::applicationDirPath() ?
Stanfillirenfro
15th January 2014, 13:36
Hi Lesiok!
Of courses!
The initial idea was to load different images from a list, each image being represented by its name. So I had to get to the file in which the images are stored and to select an image. To be able to change the name of each image in the path, I thought I could use QCoreApplication::applicationDirPath(), but unfortunately I failed.
I finally proceed as followed:
QStringList listImages;
QString str = "C:/Users/File/Desktop/imageFile/";
for(int i = 0; i<listImages.size(); i++)
{ if(listImages[i])
str.append(listImages[i])
image.load(str);
m_image = new QLabel(this);
m_image->setPixmap(image);
On this way I could solve my problem.
Thanks for your attention.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.