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

QTranslator::load with filename and no directory does not use QCoreApplication::applicationDirPath() as default path for non-Symbian system

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.4.0 RC
    • 4.8.3, 5.4.0 Beta
    • Documentation
    • None
    • Windows Home 7.

    Description

      If QTranslator::load is called with a filename and no directory, QCoreApplication::applicationDirPath() is not used as the default path for non-Symbian OS. The logic in #ifdef Q_OS_SYMBIAN for dir.isEmpty() should also be included in the #else clause of the #ifdef. Without this, the current directory is used instead which on Windows 7 defualts to the level above the directory where the .exe file is created. This problem occurs in the example hellotr.

      The example program does work correctly if the call to load is modified to provide QCoreApplication::applicationDirPath() as the directory argument to load.

      bool QTranslator::load(const QString & filename, const QString & directory,
                             const QString & search_delimiters,
                             const QString & suffix)
      {
          Q_D(QTranslator);
          d->clear();
      
          QString fname = filename;
          QString prefix;
          if (QFileInfo(filename).isRelative()) {
      #ifdef Q_OS_SYMBIAN
              //TFindFile doesn't like path in the filename
              QString dir(directory);
              int slash = filename.lastIndexOf(QLatin1Char('/'));
              slash = qMax(slash, filename.lastIndexOf(QLatin1Char('\\')));
              if (slash >=0) {
                  //so move the path component into the directory prefix
                  if (dir.isEmpty())
                      dir = filename.left(slash + 1);
                  else
                      dir = dir + QLatin1Char('/') + filename.left(slash + 1);
                  fname = fname.mid(slash + 1);
              }
              if (dir.isEmpty())
                  prefix = QCoreApplication::applicationDirPath();
              else
                  prefix = QFileInfo(dir).absoluteFilePath(); //TFindFile doesn't like dirty paths
              if (prefix.length() > 2 && prefix.at(1) == QLatin1Char(':') && prefix.at(0).isLetter())
                  prefix[0] = QLatin1Char('Y');
      #else
              prefix = directory;
      #endif
              if (prefix.length() && !prefix.endsWith(QLatin1Char('/')))
                  prefix += QLatin1Char('/');
          }
      }
      

      Attachments

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

        Activity

          People

            docteam Qt Documentation Team
            batesmotel34 Robin Christine Burrr
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes