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

QString: wrong compare - same letter different result

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.8.0
    • None
    • macOS 10.12.3 (16D32), Qt 5.8.0 precompiled binary

    Description

      Expected result: Must be the same ( file main.cpp included / copy&paste example wont work I think )

      #include <QtCore>
      
      int main(int argc, char *argv[])
      {
          QSet<QString> set;
          set.insert("ř");
          set.insert("ř");
      
          qDebug() << set;
      
          QString textA = "ř";
          QString textB = "ř";
      
          if (textA != textB)
              qDebug() << "ERROR: these are the same letters";
          if (textA.toUtf8() != textB.toUtf8())
              qDebug() << "ERROR: these are the same letters";
      }
      

      output

      QSet("ř", "ř")
      ERROR: these are the same letters
      ERROR: these are the same letters

      "wrong" letter come as returned path from QFileSystemWatcher.
      I get the name from this ( macOS io functions ) It work perfectly for any encoding ( czech / chinese / thai )

       
      QString name = QString::fromLocal8Bit(attrs.name + attrs.name_info.attr_dataoffset);
      

      But then I start watching folder using

       
      QFileSystemWatcher::addPath(const QString &file)
      

      It works correctly for chinese / thai or most unicode characters.
      But when in pathname is e.g. "ř" and directory is changed

      void directoryChanged(const QString &path, QPrivateSignal);
      

      QFileSystemWatcher returns path which looks correctly looks the same, but it it not same when try to compare QStrings.

      In some hex editor it looks like this

      QString textA = "≈ô";     // same letters, but stored differentely
      QString textB = "rÃå";
      

      So how it is that QString stores same paths/letters with different way.

      Attachments

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

        Activity

          People

            laknoll Lars Knoll
            fbucek fbucek
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes