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

Undocumented breaking changes in QCollator in Qt 5.14

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.14.2, 5.15.0 Alpha
    • 5.14.0
    • Core: Other
    • None
    • Windows
    • 41b2c477b771e7c214d09138af1a48701f573912 (qt/qtbase/5.14)

    Description

      First I noticed new lines in the output when testing my applications with Qt 5.14:

      Invalid parameter for QCollator::compare()

       I quickly concluded that this is caused by empty strings as input to QCollator::compare(). Checked the docs - it didn't say there are any restrictions on inputs, so I thought it's safe to ignore the issue. But no: I noticed that my file manager sorts files totally wrong, and here's the minimal repro:

      #include <QCollator>
      #include <QDebug>
      
      int main()
      {
        QCollator coll;
        coll.setNumericMode(true);
      
        const QString left{};
        const QString right{"sample"};
      
        qInfo() << left << "<" << right << ":" << (coll.compare(left, right) < 0);
        qInfo() << right << "<" << left << ":" << (coll.compare(right, left) < 0);
      
        return 0;
      }
      

      It prints 'false' both ways as if an empty string equals a non-empty one.
      To be more precise, it seems that not all empty strings are subject to this breaking change, only null strings
      (QString{}, but not QString{""}). And this is a problem for two reasons:
      1) In my opinion, the distinction between null strings and empty strings is Qt's internal implementation detail. A "string" is a computer science abstraction, and at this level of abstraction it shouldn't matter to algorithms (like sort()) exactly in what way the certain string is empty (doesn't contain any text).
      2) Qt classes themselves readily return null strings instead of empty non-null string. For example, the reason my file manager broke is because QFileInfo::extension() returns a null string for a file with no extension (e. g. "Makefile"). This results in inconsistent API between various Qt classes.
       

      Attachments

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

        Activity

          People

            Eddy Edward Welbourne
            alexium Alex
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes