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/appimage/ < 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 imagewhen 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();
#endificon.addFile(imageDir + "/1.png");
@ -
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.