Locale set to german | What sort order of strings to expect?
-
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.
-
Hi,
Which version of Qt are you using ?
Which exact locale are you using ? -
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.
@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.
-
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?
-
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 1Which 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.
-
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 1Which 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.
@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.
-
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
@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?
-
@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?
@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.
-
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. -
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.@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-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).
@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.
-
@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.
@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...)