PDA

View Full Version : QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"



fengtian.we
23rd May 2007, 15:46
My Code:



#include <QtGui/QApplication>
#include <QMessageBox>

int main(int argc, char *argv[])
{
QApplication *app=new QApplication(argc, argv);
QString localFileName="file.text";
QFile *file=new QFile(localFileName);
if(file->open(QIODevice::ReadWrite))
{
QMessageBox::information(0,"Error: Cannot open["+file->fileName()+"] "+file->errorString());
return 0;
}
return app->exec();
}


this will output:Error: Cannot open[file.text] Unknow error.

?????? why??

marcel
23rd May 2007, 15:52
QFile::open returns TRUE on success and false if it fails.
So you're testing wrong there.
Switch to:


if(!file->open(QIODevice::ReadWrite))

jpn
23rd May 2007, 15:55
Re-check the if-clause. QFile::open() returns true if successful; otherwise returns false.

fengtian.we
23rd May 2007, 15:58
OH!!!!!!!!!!!!!!!!!!!!!!!!! God!!!! :(

is so low problem!!!! :(

I'm a fool!~~~ thank you Sir~ thank you~~ :(