Important: Please read the Qt Code of Conduct -

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 which infact is a folder and thus I need to change to the folder where the 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()+"/";

    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.

  • Moderators

    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": 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

Log in to reply