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. Where are files typically saved when a relative path is used - Windows and Mac

Where are files typically saved when a relative path is used - Windows and Mac

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.2k 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.
  • F Offline
    F Offline
    fs_tigre
    wrote on last edited by
    #1

    Hi,

    I have a simple question about file location when saved with relative paths. I never thought about this since I have been using absolute paths for most of what I have done until now that I have been working in two different Operating Systems (Windows and Mac) and I'm getting tire of changing paths. I change all of my QFiles to be relative and everything worked fine I just cannot find the files.

    Where are files typically saved when a relative path was used?

    For instance, where should I expect this file to be saved?

    @ QFile file( "sample.txt" );
    if ( file.open(QIODevice::WriteOnly | QIODevice::Text)@

    Thanks a lot

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      This will point to your working directory: "QDir::currentPath()":http://qt-project.org/doc/qt-5.1/qtcore/qdir.html#currentPath

      The working directory will depend on how are you starting the app and it can vary from the executable location, a shortcut location to an arbitrary path if you're starting the app from the command line.

      Relative paths are not very manageable because of that and you should think about prepending one of the standard paths like "QCoreApplication::applicationDirPath()":http://qt-project.org/doc/qt-5.1/qtcore/qcoreapplication.html#applicationDirPath or one of the "QStandardPaths::standardLocations(...)":http://qt-project.org/doc/qt-5.1/qtcore/qstandardpaths.html#standardLocations depending on what you want to do exactly.

      edit: Also keep in mind that working directory might not be writable, which is usually the case for windows applications installed to "program files" as writing to it requires administrative privilages.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        crisdeveloper
        wrote on last edited by
        #3

        check if the txt files is not saved inside your root folder where your project is located.

        i created a simple notepad and the txt files is saved inside the folder of my project.

        Cristiano de Araujo Bezerra

        "there´s nothing most sexy than your brain".

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fs_tigre
          wrote on last edited by
          #4

          bq. Relative paths are not very manageable because of that and you should think about prepending one of the standard paths like QCoreApplication::applicationDirPath() [qt-project.org] or one of the QStandardPaths::standardLocations [qt-project.org] depending on what you want to do exactly.

          I will look into this.

          bq. check if the txt files is not saved inside your root folder where your project is located.

          No, it is definitely not in the root folder.

          Thanks

          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