To clear for my previous post. Under Linux + GCC4.6.x, We can use UTF-8 BOM in *source* files, not in *header* files. So if use UTF-8 encoding and with BOM, the source file should can cross-platform. In Creator, see https://codereview.qt-project.org/11851 It's easy to add/delete UTF-8 BOM now.
2012/4/23 Loaden <loa...@gmail.com> > 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. > > No, Under Linux GCC, the source files saved as UTF-8 *with* BOM too. It's > works fine when it's Windows either Linux. > So, That make sure my application is cross-platform. > > For now, the code will works fine with Qt4 either Qt5, under Windows or > Linux. > >> #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(); >> } >> > > The current question is: Shall we need or no-need to use UTF-8 encoding as > default? > I thought we should use UTF-8 as default, Because it's the better way for > cross-platform. > What do you think? > Has anyone working for this? > > > 2012/4/23 1+1=2 <dbzhang...@gmail.com> > >> 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 <loa...@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(); >> >> } >> > >> > > > > -- > Best Regards > Yuchen > > -- Best Regards Yuchen
_______________________________________________ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development