Reputation: 125
I have the issue of displaying a QImage on Mac;
QImage image0("../Images/image0.png");
The image is displayed fine on Windows and Ubuntu. This is definitely a problem with the ../ because if the full file path is used on Mac, the image is displayed correctly (I really do not want to use the full file path).
Any help is appreciated, thanks.
Upvotes: 1
Views: 1204
Reputation: 11754
With Mac applications once they're built you have a Application.app
file which contains a directory structure with your Application
binary inside, so the path is relative to that. Using the resource system will make your life much easier in this case, as you can register them and Qt will compile them in.
If you right click on your application you can select View Package Contents
and you'll be able to see the structure on the files.
Upvotes: 1
Reputation: 5718
That file path will try to access the file relative to the application's current directory (accessible through Qt with QDir::current()
). If you haven't explicitly set this it may well be different between platforms. I suspect what you're actually trying to do is access the image relative to the application executable, which is available through QCoreApplication::applicationDirPath()
. I find relative paths are best avoided for GUI apps.
Upvotes: 1