[Development] Why we *have to* remove codecFor... ?

1+1=2 dbzhang800 at gmail.com
Mon Apr 23 00:06:12 CEST 2012


Hi Loaden,

Seems you still use two different sets of source code.

 * Under MSVC 2010, source files saved as UTF8 with BOM.
 * Under Linux GCC, source files saved as UTF8 without BOM.

which means your application is not corss-platform.

And of course, this is a defect of C++ instead of Qt. You should be
aware that there are two character set related to the issue.

 * the set in which source files are written (the source character set),
 * and the set interpreted in the execution environment (the execution
character set).

But unfortunately, even in the era of the C++11, by introducing u8" "
/ u" "/ U" " , only execution character set was solved.

However, if you still use different source codes for different
platforms, like you have done with Qt4, this is still not a problem
for you.

Debao

2012/4/22 Loaden <loaden at gmail.com>:
> Thanks for help!!
> I just test on Windows 7 (MSVC2010) and Linux (GCC 4.6.2), both (Win
> / Linux, Qt4 / Qt5)  works well use below code.
>
>>
>> #include <QApplication>
>> #include <QTextStream>
>> #include <QLabel>
>> int main(int argc, char *argv[])
>> {
>> #ifdef Q_CC_MSVC
>>     #pragma execution_character_set("UTF-8")
>> #endif
>>     QApplication app(argc, argv);
>>     QString str = QString::fromUtf8("Hello世界World!你好!");
>>     QTextStream out(stdout);
>>     out << str << ", strlen=" << strlen("中文") << ", sizeof=" <<
>> sizeof("中文") << endl;
>>     QLabel *label = new QLabel(str + QObject::trUtf8("Hello世界World!你好!"));
>>     label->show();
>>     return app.exec();
>> }
>



More information about the Development mailing list