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
Forum Updated to NodeBB v4.3 + New Features

QFile with relative filename

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.6k 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.
  • J Offline
    J Offline
    Joachim W
    wrote on 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?

    aha_1980A raven-worxR 2 Replies Last reply
    0
    • J Joachim W

      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?

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by aha_1980
      #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

        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?

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on 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 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

          • Login

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