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. QFile with relative filename

QFile with relative filename

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.5k Views
  • 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.
  • J Offline
    J Offline
    Joachim W
    wrote on 11 Mar 2018, 20:44 last edited by
    #1

    How to open a QFile with a filename that is either absolute or relative to the current working directory?

    QFile::QFile(const QString &name, QObject *parent) only works with absolute paths, right?

    I know that I could use applicationDirPat to convert a relative path into an absolute one. However, I cannot believe that I have to hack this on my own. Isn't my request so simple and standard that it should have a ready-made solution in Qt?

    A R 2 Replies Last reply 11 Mar 2018, 20:51
    0
    • J Joachim W
      11 Mar 2018, 20:44

      How to open a QFile with a filename that is either absolute or relative to the current working directory?

      QFile::QFile(const QString &name, QObject *parent) only works with absolute paths, right?

      I know that I could use applicationDirPat to convert a relative path into an absolute one. However, I cannot believe that I have to hack this on my own. Isn't my request so simple and standard that it should have a ready-made solution in Qt?

      A Offline
      A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 11 Mar 2018, 20:51 last edited by aha_1980 3 Nov 2018, 20:53
      #2

      Hi @Joachim-W, and welcome.

      QFile::QFile(const QString &name, QObject *parent) only works with absolute paths, right?

      Says who?

      Of course name can be relative, you just have to know your current working directory, as the relative file path will be calculated from there.

      Regards.

      Qt has to stay free or it will die.

      1 Reply Last reply
      1
      • J Joachim W
        11 Mar 2018, 20:44

        How to open a QFile with a filename that is either absolute or relative to the current working directory?

        QFile::QFile(const QString &name, QObject *parent) only works with absolute paths, right?

        I know that I could use applicationDirPat to convert a relative path into an absolute one. However, I cannot believe that I have to hack this on my own. Isn't my request so simple and standard that it should have a ready-made solution in Qt?

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 12 Mar 2018, 08:06 last edited by
        #3

        @Joachim-W said in QFile with relative filename:

        QFile::QFile(const QString &name, QObject *parent) only works with absolute paths, right?

        no the paths do not need to be absolute only.
        Relative paths are resolved from the current directory - which is controlled by QDir::current()/QDir::setCurrent()

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        2
        • J Offline
          J Offline
          Joachim W
          wrote on 12 Mar 2018, 12:14 last edited by
          #4

          Thanks.
          I confirm that my problem is not with lacking support for relative paths, but with an unexpected value of QDir::current().

          1 Reply Last reply
          1

          1/4

          11 Mar 2018, 20:44

          • Login

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