芬兰客户告诉我,芬兰语的正确(区域设置)排序是:a-z,å,ä,ö。
但是QString :: localeAwareCompare()在Windows Vista的Qt 4.4.2中将其返回为:a,ä,å,b-o,ö,p-z。
#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();
}
输出:
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
我的芬兰客户得到的结果相同。这是一个错误还是我做错了什么?
答案 0 :(得分:3)
我在Windows XP上测试了Qt 4.6.2中的代码,这些字符排序正确。在您的测试用例中,我得到以下输出:
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
作为芬兰人,我可以确认您的客户对芬兰分拣订单是否正确。
那么也许你可以升级到新的Qt版本?