Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
4.4.2
-
None
Description
The example below shows a failure. Edit transbug.cpp, comment out the "#define" for FAILURE and repeat - it will now work.
Looking at the output when it fails, one can see that even if both QFile and QFileInfo reports the file as existing, and we can open it with QFile, QFileInfo::isReadable() returns false. This is what causes the code in QTranslator::load() to fail, as it uses QFileInfo::isReadable() to check whether or not a file is available for reading.
#include <QtCore> #define FAILURE int main(int argc, char **argv) { QCoreApplication a(argc, argv); #ifdef FAILURE QDir::addSearchPath("translation", a.applicationDirPath()); #endif QDir::addSearchPath("translation", ":/"); QString filename = "translation:transbug.qm"; QTranslator t; if (t.load(filename)) a.installTranslator(&t); else qWarning("No translator found"); QFileInfo fi(filename); if (fi.exists()) { qWarning("QFileInfo says it exists"); } else { qWarning("QFileInfo says it doesn't exist"); } if (fi.isReadable()) { qWarning("QFileInfo says it's readable."); } else { qWarning("QFileInfo says it's not readable."); } QFile f(filename); if (f.exists()) { qWarning("QFile says it exists!"); } else { qWarning("QFile says it doesn't exist!"); } if (f.open(QIODevice::ReadOnly)) { qWarning("We can read it."); } else { qWarning("We can't read it."); } qWarning("%s", qPrintable(a.translate("TransBug", "Failure"))); }