Simple application gives varying results on different Macs
-
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! -
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.
-
Hi and welcome to devnet,
Any chance of the two failing being 10.9.5 and 10.10.12 ?
-
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 ?
-
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
-
Sorry, I forgot the link. "Here":http://doc.qt.io/qt-5/resources.html you go, Qt's resources system