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

QCollatorSortKey gives wrong compare result

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2: Important P2: Important
    • None
    • 5.15.10
    • None
    • Qt 5.15.10 msvc2019_64 compiler version installed
    • Windows
    • 21

      QCollator with numericMode generates QCollatorSortKey that have differ results in compare function that QCollator that generates that keys.

      The easiest example of that:

      mCollator.setNumericMode(true);
      auto result = mCollator.compare("00", "10"); //-1 ok
      QCollatorSortKey key1 = mCollator.sortKey("00");
      QCollatorSortKey key2 = mCollator.sortKey("10");
      
      auto result2 = mCollator.compare("9", "10"); // -1 ok
      QCollatorSortKey key3 = mCollator.sortKey("9");
      QCollatorSortKey key4 = mCollator.sortKey("10");
      
      auto result3 = mCollator.compare("99", "100"); // -1 ok
      QCollatorSortKey key5 = mCollator.sortKey("99");
      QCollatorSortKey key6 = mCollator.sortKey("100");
      
      bool result4 = key1 < key2; //false wrong
      bool result5 = key3 < key4; //true  ok
      bool result6 = key5 < key6; //false wrong

      It seems that that QCollatorSortKey generated from QCollator not works properly when setNumericMode is set to true.

       

      I attached some example of result after sorting, the range was from 0 to 35000

       

        1. example.PNG
          28 kB
          Paweł Srebrny
        2. image-2022-11-23-12-04-46-881.png
          12 kB
          Paweł Srebrny
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            cnn Qt Core & Network
            zloty Paweł Srebrny
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes