freely
8th August 2011, 13:10
Hello,
Does anybody know what is wrong with next:
I need to create file in some directory with rw permissions on disk then write to it data and open after. On Windows and Linux, MacOS also.
For that I use next code:
...
QString outputDir = "some_dir"; // with "/" separators
QString fileName = "some_file_name" + ".dat";
QFile file(outputDir+"/"+fileName);
if (!file.open(QIODevice::WriteOnly|QFile::WriteOnly) )
{
QMessageBox::warning(0,"Could not create Project File",
QObject::tr( "\n Could not create Project File on disk"));
return false;
}
else
{
QDataStream stream(&file);
...
file.close();
}
...
On Linux ( Ubuntu ) it works ok ( file.open(…) returns true ) – file is created , written , closed ,reopened ,read. But when I run the same code on Windows file.open(…) returns false in any directory I choose. It is written in Qt docs that Qt automatically treats right directory path names ( separators ) for underlying OS ( translates “/†( default ) to underlying OS ).
I’ve tried to use QDir::toNativeSeparators(outputDir+â€/â€+fileName) inside file.open(…) but still the file couldn’t be created on Windows – file.open(…) returns false.
***
Does anybody can help/point what is wrong with creating new file on windows in this case ? ( what is wrong with file.open(…) ) ?
How to solve so that I can open new file on Windows using QFile?
Thank you in advance.
Does anybody know what is wrong with next:
I need to create file in some directory with rw permissions on disk then write to it data and open after. On Windows and Linux, MacOS also.
For that I use next code:
...
QString outputDir = "some_dir"; // with "/" separators
QString fileName = "some_file_name" + ".dat";
QFile file(outputDir+"/"+fileName);
if (!file.open(QIODevice::WriteOnly|QFile::WriteOnly) )
{
QMessageBox::warning(0,"Could not create Project File",
QObject::tr( "\n Could not create Project File on disk"));
return false;
}
else
{
QDataStream stream(&file);
...
file.close();
}
...
On Linux ( Ubuntu ) it works ok ( file.open(…) returns true ) – file is created , written , closed ,reopened ,read. But when I run the same code on Windows file.open(…) returns false in any directory I choose. It is written in Qt docs that Qt automatically treats right directory path names ( separators ) for underlying OS ( translates “/†( default ) to underlying OS ).
I’ve tried to use QDir::toNativeSeparators(outputDir+â€/â€+fileName) inside file.open(…) but still the file couldn’t be created on Windows – file.open(…) returns false.
***
Does anybody can help/point what is wrong with creating new file on windows in this case ? ( what is wrong with file.open(…) ) ?
How to solve so that I can open new file on Windows using QFile?
Thank you in advance.