Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Beginners: how to refere to a file in the same path of the application (MAC-Win)

Beginners: how to refere to a file in the same path of the application (MAC-Win)

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SherifOmran
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cptG
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tobias.hunger
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SherifOmran
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved