views:

44

answers:

1

A Finnish customer tells me that the correct (locale aware) sorting for Finnish is: a-z, å, ä, ö.

But QString::localeAwareCompare() returns it as: a, ä, å, b-o, ö, p-z in Qt 4.4.2 on Windows Vista.

#include <qapplication.h>
#include <qlocale.h>
#include <iostream>
#include <tchar.h>

int
main( int argc, char* argv[] )
{
    QLocale::setDefault ( QLocale( QLocale::Finnish ) );

    QApplication app( argc, argv );    

    QString s1 = "a";
    QString s2 = "ä";
    QString s3 = "å";
    QString s4 = "b";
    QString s5 = "o";
    QString s6 = "ö";
    QString s7 = "z";

    std::cout << "QString::localeAwareCompare( s1, s2 )=" << QString::localeAwareCompare( s1, s2 ) << "\n";
    std::cout << "QString::localeAwareCompare( s2, s3 )=" << QString::localeAwareCompare( s2, s3 ) << "\n";
    std::cout << "QString::localeAwareCompare( s3, s4 )=" << QString::localeAwareCompare( s3, s4 ) << "\n";
    std::cout << "QString::localeAwareCompare( s4, s5 )=" << QString::localeAwareCompare( s4, s5 ) << "\n";
    std::cout << "QString::localeAwareCompare( s5, s6 )=" << QString::localeAwareCompare( s5, s6 ) << "\n";
    std::cout << "QString::localeAwareCompare( s5, s6 )=" << QString::localeAwareCompare( s6, s7 ) << "\n";

    return app.exec();
}

Outputs:

QString::localeAwareCompare( s1, s2 )=-1
QString::localeAwareCompare( s2, s3 )=-1
QString::localeAwareCompare( s3, s4 )=-1
QString::localeAwareCompare( s4, s5 )=-1
QString::localeAwareCompare( s5, s6 )=-1
QString::localeAwareCompare( s5, s6 )=-1

My Finnish customer is getting the same result. Is this a bug or am I doing something wrong?

+2  A: 

I tested your code in Qt 4.6.2 on Windows XP and those characters are sorted correctly. With your test case I get the following output:

QString::localeAwareCompare( s1, s2 )=-1
QString::localeAwareCompare( s2, s3 )=1
QString::localeAwareCompare( s3, s4 )=1
QString::localeAwareCompare( s4, s5 )=-1
QString::localeAwareCompare( s5, s6 )=-1
QString::localeAwareCompare( s5, s6 )=1

And as a Finnish, I can confirm that your customer is right about the Finnish sorting order.

So maybe you could upgrade to a new Qt version?

Roku
does localeAwareCompare base on locale set in operating system? If yes, maybe that's issue?
Kamil Klimek
The customer presumably has the local set correctly in Windows. He is reporting the same problem.
Andy Brice
Roku - Thanks for checking. It seems like it is a bug in Qt 4.2.2, since fixed. I hope to upgrade to the latest Qt at some point. I guess they fixed it once they were bought by a Finnish company (Nokia). ;0)
Andy Brice
Qt (Trolltech) was "bought" by nokia long after Qt 4.2 :)
Kamil Klimek