Important: Please read the Qt Code of Conduct -

How to located image files for MAC?

  • When win32...


    Load image is Ok.

    When MAC OS

    image/ < load image success. but i want this not... <- don't load image <- don't load image

    when i coding >>icon.addFile("image/1.png"~~~~~~~; <-- want load image..

    Because When i do design form, I use the QT Designer.
    Auto Create ui_mainwindow.h
    this line icon.addFile("image/1.png"~~~~~~~; ...

  • The correct path is ... maybe with subdirs, that's up to you.

    To construct a path use this snippet:

    #ifdef Q_OS_MACX
    QString imageDir = QCoreApplication::applicationDirPath() + "/../Resources";
    QString imageDir = QCoreApplication::applicationDirPath();

    icon.addFile(imageDir + "/1.png");

  • thanks.

    But this code automatic created. -> icon.addFile("1.png");

    Because I made that desing form. That code auto created..

  • In that case you should remove the images from the designer form and set the icons programmatically in your C++ class.

    Another solution would be to put the icons into a "Qt Resource file":/doc/qt-4.8/resources.html. You can use those in "Designer:"/doc/qt-4.8/designer-resources.html as well.

  • Okay. Thanks.

    Have a good week.

Log in to reply