Beginners: how to refere to a file in the same path of the application (MAC-Win)
-
Hello guys,
this might be a naiive question, I am building an application in MAC-Windows and I use a database file that should exist in the folder of the application. My problem is : In Debug mode, I have to have the files inside the debug folder which is different that from run time folder. Also in Mac, the application file is example.app which infact is a folder and thus I need to change to the folder where the example.app is.
Any Ideas, what is the proper way to do it?
-
Not sure about the on-MacOS-the-executable-is-a-directory (?!?) thingy, never used a mac. But:
@
QString fileName=QApplication::applicationDirPath()+"/foo.bar";
@will do the trick.
See the docs for QCoreApplication::applicationDirPath(), there is a comment about MacOS that you'll surely understand, I can't comment on that as a Linux user. -
Please do not assume that you can write to files in the folder next to your application. That is in no way portable and will lead to trouble when several users end up running your application on the same computer at the same time.
Each OS has recommendations on where to put user-editable data files. Use "QDesktopServices":http://qt-project.org/doc/qt-4.8/qdesktopservices.html#storageLocation to find those.
-
which location should I use with @QDesktopServices::storageLocation@
Some files can be edited by users and some files are common for all users ex central database for all users