[Development] Why we *have to* remove codecFor... ?
Loaden
loaden at gmail.com
Sun Apr 22 16:25:35 CEST 2012
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();
> }
>
Thanks again!
But there still exist a question that why we don't use UTF-8 as default?
e.g.
> QString str("Hello世界World!你好!");
Shoule with same behaviour with:
> QString str = QString::fromUtf8("Hello世界World!你好!");
If use UTF-8 as default, then we can remove trUtf8, just use tr.
So, Why?
2012/4/22 Giuseppe D'Angelo <dangelog at gmail.com>
> On 22 April 2012 11:50, Loaden <loaden at gmail.com> wrote:
> >> (I don't have any clue about MSVC).
> >
> > That the point! In current solution, It's does't work for this case if
> use
> > MSVC Compiler.
> > My Point:
> > Please don't think about of MSVC users.
> > Or, please give me a way to fix the problem.
>
> I don't know. If that file is correct UTF-8 (with or without BOM) then
> you must find a way to tell MSVC that your input and execution
> charsets are UTF-8. If that fails for any reason (impossible / bug /
> ...), MSVC gets the nice "crap" mark Thiago was talking about.
>
> Still, you need to change those tr() to trUtf8() or set UTF-8 as the
> codec for tr. Also, notice that qDebug() is not Unicode safe -- it's
> for debugging. Use something like qDebug() << string.toUtf8().toHex()
> to be 100% sure it contains what you expect.
>
> Cheers,
> --
> Giuseppe D'Angelo
>
--
Best Regards
Yuchen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20120422/417ce3cd/attachment.html>
More information about the Development
mailing list