-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
4.6.2
-
None
-
gentoo linux, x86-64, gcc 4.4.3, Qt 4.6.2
QFile has an error() function which will return an error code representing why a given file operation failed. In addition to this it has (inherited from QIODevice) an errorString(). errorString() is returning a QString which accurately describes the error while error() is returning an error code which is far more general (while still accurate). QFile::FileError does have proper values for the various error situations, it is just not returning them.
For example, the following code:
#include <QFile>
#include <QDebug>
QString fileErrorString(QFile::FileError error) {
switch(error) {
case QFile::NoError: return "No error occurred.";
case QFile::ReadError: return "An error occurred when reading from the file.";
case QFile::WriteError: return "An error occurred when writing to the file.";
case QFile::FatalError: return "A fatal error occurred.";
case QFile::ResourceError: return "A resource error occured.";
case QFile::OpenError: return "The file could not be opened.";
case QFile::AbortError: return "The operation was aborted.";
case QFile::TimeOutError: return "A timeout occurred.";
case QFile::RemoveError: return "The file could not be removed.";
case QFile::RenameError: return "The file could not be renamed.";
case QFile::PositionError: return "The position in the file could not be changed.";
case QFile::ResizeError: return "The file could not be resized.";
case QFile::PermissionsError: return "The file could not be accessed.";
case QFile::CopyError: return "The file could not be copied.";
default:
case QFile::UnspecifiedError: return "An unspecified error occurred.";
}
}
int main() {
// a regular user shouldn't be able to open this file...
QFile file("/etc/shadow");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << file.errorString();
qDebug() << fileErrorString(file.error()); // I expect this to print "The file could not be accessed."
}
}
yields the following (when run as an unprivileged user):
"Permission denied"
"The file could not be opened."
Since QFile::FileError has enough enumerations to be more specific, I would expect it's value to represent the same error as errorString() returns.