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

QDir/QDirIterator drop files whose names are not valid UTF-8

XMLWordPrintable

    • Linux/X11

       

      QDir::entryList() / QDir::entryInfoList() (and by implication QDirIterator) skip directory entries whose byte sequences for the filename are not valid UTF-8. This makes files created with legacy 8-bit encodings (e.g., ISO-8859-15) invisible to Qt applications. Some Qt-based file managers (e.g., pcmanfm-qt) can list these files, so this appears to be a Qt API limitation rather than an OS limitation.

      Steps to reproduce

       mkdir -p ~/encoding_test
      cd ~/encoding_test
      
      touch "bl$(printf '\xC3\xA4')-utf.txt"
      touch "bl$(printf '\xE4')-iso.txt"

       

       #include <QCoreApplication>
      #include <QDir>
      #include <QFile>
      #include <QStringList>
      #include <QTextStream>
      #include <QTextCodec>int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
        
          QTextStream out(stdout);
          QDir dir("/home/irfan/encoding_test");    QStringList entries = dir.entryList(QDir::NoDotAndDotDot | QDir::AllEntries);    for (const QString &entry : entries) {
              QString entry2(QString::fromUtf8(entry.toLatin1()));
              out << entry.length() << ": " << entry /*<< "\t" << entry2.length() << ": " << entry2*/ << "";
          }
          return 0;
      }

       

      When you run above code only the UTF-8 file (blä-utf.txt) is listed,Qt APIs that enumerate directory entries should not drop files whose names are not valid UTF-8. At minimum

       

       

       

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

            thiago Thiago Macieira
            irfan.omair@digia.com Irfan Omair
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes