How to located image files for MAC?



  • When win32...

    appfolder/
    appfolder/image/1.png
    2.png
    appfolder/app.exe
    icon.addFile("image/1.png"~~~~~~~;

    Load image is Ok.

    When MAC OS

    app.app/
    app.app/Contents/
    app.app/Contents/MacOS/app

    image/ < load image success. but i want this not...

    app.app/Contents/MacOS/image/1.png <- don't load image
    app.app/Resources/image/1.png <- don't load image

    when i coding >>icon.addFile("image/1.png"~~~~~~~;
    app.app/Resources/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

    app.app/Contents/Resources ... maybe with subdirs, that's up to you.

    To construct a path use this snippet:

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

    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.