Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-2892

QDir::addSearchPath(), QFileInfo::isReadable() and QTranslator::load issue

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Out of scope
    • Icon: Not Evaluated Not Evaluated
    • Some future release
    • 4.4.2
    • Core: I/O
    • None

      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")));
      }
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            stormols Marius Storm-Olsen
            admin Administrator
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes