QFile with relative filename
-
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?
-
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.
-
@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()