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

Loaden loaden at gmail.com
Mon Apr 23 03:00:41 CEST 2012


>
> 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 <dbzhang800 at 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 <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();
> >> }
> >
>



-- 
Best Regards
Yuchen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120423/ff4e25f7/attachment.html>


More information about the Development mailing list