Solved QFile open(QIODevice::WriteOnly) always giving false
-
Hi
I have code to write buffer to a new file. But it always return false. Can someone suggest the reason ?
QFile fileWrite(); fileWrite.open(QIODevice::WriteOnly); fileWrite.setFileName(imageDirectory + "/TAGGED/" + _imageList.at(i).fileName()); qDebug() << fileWrite.fileName(); // gives the correct file name if (fileWrite.open(QIODevice::WriteOnly )){ //doesnot enter this loop fileWrite.write(imageBuffer); fileWrite.close(); } else { qDebug() << fileWrite.openMode(); //gives NOT OPEN qDebug() << "Geotagging failed. Couldn't write to an image"; return; }
-
Hi,
the usual suspects:- the directory is write protected
- the directory does not exist
- the file name is illegal
-Michael.
-
Hi
Did you check why it fails with
http://doc.qt.io/qt-5/qfiledevice.html#error
? -
Hi,
To add to my fellows, you start by opening a file without any name and then you try to open it again. That looks suspicious.
-
I am getting "The file could not be opened" error with error code 5 (QFileDevice::OpenError).
-
@saitej
and does the "TAGGED" folder exists? -
That was the mistake.
Thanks -
Error code 5 generally means you don't permission to open the file . Please check permissions