如何在代码中引用Resources文件夹 [英] How to reference Resources folder in code
问题描述
我正在将一个c ++ Qt应用程序从Windows移植到OSX,并且无法围绕.app包概念。我希望有人可以帮助我理解。
我的可执行文件存放在这里:MyProgram.app/Content/MacOS/MyProgram.exe
我的资源文件夹位于这里:MyProgram.app/Content/Resources /
在我的代码中,我使用相对路径来引用资源文件夹中的项目: / p>
../ Resources / something.png
如果我打开.app包,直接运行.exe。
但这不是.app包是如何工作的。用户应该点击Finder中的.app包来运行程序。但是在这种情况下,我的相对路径不再工作,这是我不明白。
有谁知道我的问题,我怎么能解决它? p>
QApplication :: applicationDirPath()
http: //doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath
I'm porting a c++ Qt application from Windows to OSX and cannot wrap my head around the .app bundle concept. I hope someone can help me understand.
My executable lives here: MyProgram.app/Content/MacOS/MyProgram.exe
My resource folder lives here: MyProgram.app/Content/Resources/
In my code I use a relative path to reference items in the resource folder:
"../Resources/something.png"
This works great if I open the .app bundle and run the .exe directly.
But that is not how the .app bundle is meant to work. The user is supposed to click on the .app bundle in the Finder to run the program. But in that case my relative path no longer works, and this is what I don't understand.
Does anyone understand my problem and how I can fix it?
QApplication::applicationDirPath()
http://doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath
这篇关于如何在代码中引用Resources文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!