Locale set to german | What sort order of strings to expect?
-
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...)