⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

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");


    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.

  • Thanks for the reply.

    No. I tested with png image files. I have the same problem.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Any chance of the two failing being 10.9.5 and 10.10.12 ?

  • Yes! How did you know?

  • Lifetime Qt Champion

    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 ?

  • 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?

  • Lifetime Qt Champion

    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

  • I am not sure what you mean. Can you please elaborate or point me to the right documentation?

  • Lifetime Qt Champion

    Sorry, I forgot the link. "Here":http://doc.qt.io/qt-5/resources.html you go, Qt's resources system

Log in to reply