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

QCollator::sortKey gives wrong sorting for numbers on Windows

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 5.15.2, 6.7.2
    • None
    • Windows

      On Windows calling QCollator::sortKey gives a QCollatorSortKey that results in wrong sorting of numbers. Specifically the numbers 0-9 get sorted into alphabetical characters like A, 0, B, C, 1, D, 2, 3, 4, E, 5, F, 6, G, 7, 8, 9, H, I, ....

      This Python code demonstrates the issue:

      from PySide6.QtCore import QCollator, QLocale
      
      locale = QLocale('en')
      collator = QCollator(locale)
      
      print(collator.sortKey('A') < collator.sortKey('C'))  # prints True, as expected
      print(collator.sortKey('1') < collator.sortKey('C'))  # prints False, expected is True
      print(collator.sortKey('1') < collator.sortKey('D'))  # 1 sorts between C and D

      The issue is reproducible on both Qt 5.15.2 and Qt 6.7.2. This only happens on Windows, on Linux and macOS the sorting seems fine.

      Using collator.compare works as expected, collator.compare('1', 'A') correctly returns -1. But this is not a workaround for all use cases.

      Using collator.setNumericMode(True) also results in proper sorting of single digits and alphabetical characters, but as described in QTBUG-108756 this also has issues.

       

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

            thiago Thiago Macieira
            phw Philipp Wolfer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes