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. How to find what directory QFile is opening files from
Qt 6.11 is out! See what's new in the release blog

How to find what directory QFile is opening files from

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 5.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.
  • A Offline
    A Offline
    abuv
    wrote on last edited by
    #1

    How do I know what directory the QFile class is finding my files to open? Is it possible to specify what local directory I want to pull files from?

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      If you give QFile a relative path, QFile will use your Working Directory (also known as the Current Directory). You can use the "QDir":http://doc.qt.io/qt-5/qdir.html class to get and set your working directory. See QDir::currentPath() and QDir::setCurrentPath().

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        If you path doesn't start with / on *nix system then it's relative to the current path. If you want to e.g. load file from directories in the same folder as your application you can use QCoreApplication::applicationDirPath() to build your paths

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        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