QFile with relative filename
-
wrote on 11 Mar 2018, 20:44 last edited by
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?
-
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?
Lifetime Qt Championwrote on 11 Mar 2018, 20:51 last edited by aha_1980 3 Nov 2018, 20:53Hi @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.
-
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?
@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() -
wrote on 12 Mar 2018, 12:14 last edited by
Thanks.
I confirm that my problem is not with lacking support for relative paths, but with an unexpected value of QDir::current().
1/4