Simple application gives varying results on different Macs
-
wrote on 25 Feb 2015, 20:16 last edited by
Hello everyone,
I am a beginner with Qt. I made a very simple application to display an image.
I compiled and ran the application on 4 Macs. On 2 of them the image was displayed in the window, on the other 2 no image was displayed. I have QMake version 2.01a and Qt version 4.8.6 on all the machines.
Mac1 OS X version 10.7.5
Mac2 OS X version 10.10.12
Mac3 OS X version 10.6.8
Mac4 OS X version 10.9.5@
#include <QtGui>int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QGraphicsScene scene;
QGraphicsView view(&scene);QImage img("Test-Pattern.jpg");
scene.addPixmap(QPixmap::fromImage(img));
view.show();
return a.exec();
}
@I am not sure if this problem is due to different OS versions or due to my code.
I would really appreciate any help. Thanks! -
wrote on 25 Feb 2015, 20:35 last edited by
Assuming the image was available on all four machines you might be missing the Qt image plugins on two of them. I am pretty sure you need this for jpeg files.
If you repeat the same test using a PNG image instead of JPG and it works on all four then this is very likely your problem.
-
wrote on 25 Feb 2015, 20:49 last edited by
Thanks for the reply.
No. I tested with png image files. I have the same problem.
-
Hi and welcome to devnet,
Any chance of the two failing being 10.9.5 and 10.10.12 ?
-
wrote on 25 Feb 2015, 21:06 last edited by
Yes! How did you know?
-
Intuition ;) And the fact that Apple changed the way it sets the working directory since 10.9 that broke some applications using QDir::currentPath() rather than QCoreApplication::applicationDirPath() to get the folder where the executable was located.
Anyway, for your problem: "Test-Pattern.jpg" is a relative path. Where is it really located ?
-
wrote on 25 Feb 2015, 21:20 last edited by
The image file is located in the same directory as my source code.
I just tested with full path and the the application displays images! Thank you!
Can you suggest what I need to do make my application work for relative paths?
-
Put the files in the right place and on OS X it's not the same folder as your application.
However if that file isn't too big you can also embed it in your executable
-
wrote on 25 Feb 2015, 22:11 last edited by
I am not sure what you mean. Can you please elaborate or point me to the right documentation?
-
Sorry, I forgot the link. "Here":http://doc.qt.io/qt-5/resources.html you go, Qt's resources system
7/10