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 377 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 andi456

    Hi,

    after an extensive search on the net, I got confused about this issue. The problem arises with german umlauts (Umlaute: ä, ö, ü) that - as a german speaker - one would expect to be sorted as if they were written like so: ä -> ae, ö -> oe, ü -> ue.

    But by default the sorting routines of qt (underlying qsortproxyfiltermodel for example) seem to put umlauts even behind "z". During my research I learned that this is, what Skandinavians would expect for their diacritical symbols and in some cases this also true for german umlauts.

    In my sortproxmodel I've already set "setSortLocaleAware(true)", but the result is the same. Are there any other options that I might have overlooked?

    Kind regards.

    S Offline
    S Offline
    SimonSchroeder
    wrote last edited by
    #3

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

    one would expect to be sorted as if they were written like so: ä -> ae, ö -> oe, ü -> ue

    That is only partially right. Quickly looked it up: the DIN 5007 specifies two different sorting orders: Variant 1 specifies umlauts the same as the letter without the umlaut, i.e. ä -> a, ö -> o, ü -> u (and if words are otherwise the same the non-umlaut comes before the umlaut, e.g. Mutter before Mütter). Variant 2 is the sorting for names, e.g. in phone books, which is the sorting you proposed. However, when you are just writing down the alphabet, the umlauts usually come after the standard Latin characters. Another thing might be just binary sorting of the characters: In German codepages or in Unicode the umlauts come after the standard Latin characters as well. So, without a locale umlauts certainly come after 'z' (and it has nothing to do with the Skandinavians).

    This is just to what expect (i.e. is one of the two variants of DIN 5007), but I don't know where the problem is with Qt.

    1 Reply Last reply
    2
    • 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