Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Locale set to german | What sort order of strings to expect?

Locale set to german | What sort order of strings to expect?

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 375 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andi456
    wrote last edited by
    #4

    Hi, thanks for your answers:
    To find out the current locale as determined by the Qt-framework itself, i used a QCollator variable and its locale() method. This results in the following output:
    QLocale(German, Latin, Germany)

    The version of qt is: 6.10.1.

    Well, regarding the different ways of ordering umlauts in german: that's exactly, what got me confused and let to my post. Should I expect the dictionary way of sorting or the phonebook way or the unicode way?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote last edited by
      #5

      What does

      int main(int argc, char** argv)
      {
          QApplication app(argc, argv);
          QCollator collator;
          qDebug() << collator.compare("aaaaa", "äääää");
          qDebug() << collator.compare("bbbbb", "äääää");
          qDebug() << collator.locale();
          return 0;
      }
      

      return for you? Here on windows11, Qt 6.12 I get

      -1
      1
      

      Which looks correct. Did not yet tested in a bigger environment. Would be nice if you can prepare one so we can check. A QStringListModel + QSortFilterProxyModel should do the job when I understand your problem correctly.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        What does

        int main(int argc, char** argv)
        {
            QApplication app(argc, argv);
            QCollator collator;
            qDebug() << collator.compare("aaaaa", "äääää");
            qDebug() << collator.compare("bbbbb", "äääää");
            qDebug() << collator.locale();
            return 0;
        }
        

        return for you? Here on windows11, Qt 6.12 I get

        -1
        1
        

        Which looks correct. Did not yet tested in a bigger environment. Would be nice if you can prepare one so we can check. A QStringListModel + QSortFilterProxyModel should do the job when I understand your problem correctly.

        A Offline
        A Offline
        andi456
        wrote last edited by
        #6

        @Christian-Ehrlicher I get the same results, while the locale remains the same as i've already reported. I'll adapt my proxymodel code to the collator results and report back what happens.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andi456
          wrote last edited by
          #7

          Ok, I can tell that sorting QString variables with the QCollator Class seems to work, while sorting them with the "<" operator seems to result in binary sorting of the characters

          Christian EhrlicherC 1 Reply Last reply
          0
          • A andi456

            Ok, I can tell that sorting QString variables with the QCollator Class seems to work, while sorting them with the "<" operator seems to result in binary sorting of the characters

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote last edited by
            #8

            @andi456 said in Locale set to german | What sort order of strings to expect?:

            while sorting them with the "<" operator seems to result in binary sorting of the characters

            Yes, how should it work otherwise?

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            A 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              @andi456 said in Locale set to german | What sort order of strings to expect?:

              while sorting them with the "<" operator seems to result in binary sorting of the characters

              Yes, how should it work otherwise?

              A Offline
              A Offline
              andi456
              wrote last edited by
              #9

              @Christian-Ehrlicher Well, I thought that the option "setSortLocaleAware" in QSortFilterProxyModel would have had the effect of - so to say - making the "<" operator aware of the Locale it is operating in. That's why I came across the QCollator Class in order to check out, if Qt was indeed in the German Locale.

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote last edited by
                #10

                The operator < compares two QStrings directly - how should a locale here come into play?
                I'll take a look on it why setSortLocaleAware() is not using QCollator though.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                A 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  The operator < compares two QStrings directly - how should a locale here come into play?
                  I'll take a look on it why setSortLocaleAware() is not using QCollator though.

                  A Offline
                  A Offline
                  andi456
                  wrote last edited by
                  #11

                  @Christian-Ehrlicher Maybe, it works, if one does not need to reimplement the "lessThan" method as I had to in order to do a two level sort (first by an integer value and then by a QString).

                  Christian EhrlicherC 1 Reply Last reply
                  0
                  • A andi456

                    @Christian-Ehrlicher Maybe, it works, if one does not need to reimplement the "lessThan" method as I had to in order to do a two level sort (first by an integer value and then by a QString).

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote last edited by
                    #12

                    @andi456 said in Locale set to german | What sort order of strings to expect?:

                    if one does not need to reimplement the "lessThan" method as I had to in order to do a two level sort (first by an integer value and then by a QString).

                    So you do your own comparision? Then setSortLocalAware can do anything for you since you don't respect it as you already wrote.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    A 1 Reply Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      @andi456 said in Locale set to german | What sort order of strings to expect?:

                      if one does not need to reimplement the "lessThan" method as I had to in order to do a two level sort (first by an integer value and then by a QString).

                      So you do your own comparision? Then setSortLocalAware can do anything for you since you don't respect it as you already wrote.

                      A Offline
                      A Offline
                      andi456
                      wrote last edited by
                      #13

                      @Christian-Ehrlicher Yes, I had to implement my own comparison for the reason I just mentioned, but I haven't been sure how Locale settings and other options affect QString comparison. Now, I know that using QCollator is the way to go. (I was actually thinking about including ICU directly, but it would have been sort of an overkill...)

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved