Why can't QFile read from the "~" directory?
Posted
by hurikhan77
on Stack Overflow
See other posts from Stack Overflow
or by hurikhan77
Published on 2010-05-12T06:40:37Z
Indexed on
2010/05/12
6:44 UTC
Read the original article
Hit count: 277
I've tried the following short example to find out about a bug in a bigger program I am working on. It looks like QFile doesn't support unix (or the shell's) notation for the home directory:
#include <QFile>
#include <QDebug>
int main()
{
QFile f("~/.vimrc");
if (f.open(QIODevice::ReadOnly))
{
qDebug() << f.readAll();
f.close();
}
else
{
qDebug() << f.error();
}
}
As soon as I replace the "~" with my real home directory path, it works. Is there an easy workaround - some setting to enable? Or do I have to go the "ugly" way and ask QDir for the home directory of the current user and prepend that manually to each path?
© Stack Overflow or respective owner