Reputation: 129
i want to create a file in /home/username/ so i write some codes like this
#define CONFIG_FILE_PATH "~/.config/xmlfile
QFile file(CONFIG_FILE_PATH);
if (!file.open(QFile:ReadOnly | QFile::Text))
{
if (!file.open(QFile::WriteOnly | QFile::Text))
{
//print error message
}
else
{
//dosomething
file.close();
}
}
but when i run the program, i cannot find "xmlfile" i tried
sudo find / -name *xmlfile*
but found nothing and the program do not show any error messages.
is there some rules with the character ~ when using QFile?
Thanks in advance.
Upvotes: 0
Views: 126
Reputation: 11754
In my experience with QFile
it doesn't like any 'special' characters within the file path such as tilde, you're best off using relative or full paths. If you use QDir::homePath()
it'll return a string to the current user home directory (see the documentation here: QDir special paths.
Upvotes: 1