Thanks for reply! I don't care the reason now, I just want know how to make it work. I am try UTF-8 of the source file, with or not with UTF-8 BOM, and try fromLatin1/Utf8/Ascii too. And all tried is failed!
In MSVC2010, If use some Chinese (CJK) strings, We have to save the source file as UTF-8 with BOM format. I am also try UNICODE (with or without BOM) too. It's does't work too. 2012/4/22 Robin Burchell <robin...@viroteck.net> > 2012/4/22 Loaden <loa...@gmail.com>: > > Hi, All! I am only a physics teacher from China. It makes me > confused that > > I just noticed the codecFor... function is removed for now. > > It's removed primarily for sanity reasons. Not being able to reliably > know what fromAscii/toAscii are actually going to do mean that they > become pretty much unusable in library code (but there was never any > warning, meaning it was a gigantic hard-to-debug trap) - and this is > not even mentioning that they are called "fromAscii" and "toAscii", > not "fromSomeMagicGlobalLocale" and "toSomeMagicGlobalLocale". > > Not having to worry about this means that there's a lot less chance of > people shooting themselves in the foot, since prior to this, using > those methods was almost never what you actually wanted when writing > "portable" Qt code, and as a coincidence, should help performance a > bit since codecs are no longer involved (plus the ASCII conversions > are now inlined, from memory). > > > But please let's me know how to make this work with *MSVC2010*? > > Tell MSVC to save in unicode format, and use QString::fromUtf8 instead > of QString::fromAscii. Some searching shows that this is possible > fairly easily: > http://stackoverflow.com/questions/5406172/utf-8-without-bom-in-visual-studio-2010 > > There has also been talk about making QString's char* methods use to > utf8 (meaning you'd be able to use QString foo("bunçh øf u†f8 here"); > and it'd work fine, but I never got around to writing that, I don't > know if anyone else has started yet. > -- Best Regards Yuchen
#include <QApplication> #include <QLabel> #include <QTextCodec> #include <QTextStream> #include <QDebug> int main(int argc, char *argv[]) { #ifdef Q_OS_WIN QTextCodec *codec = QTextCodec::codecForName("GBK"); QTextCodec::setCodecForLocale(codec); #if QT_VERSION < 0x050000 QTextCodec::setCodecForCStrings(codec); QTextCodec::setCodecForTr(codec); #endif #endif QApplication app(argc, argv); QString str = QString::fromUtf8("Hello世界World!你好!"); QTextStream out(stdout); qDebug() << "Hello世界World!你好!"; out << str << endl; QLabel *label = new QLabel(str + QObject::tr("Hello世界World!你好!")); label->show(); return app.exec(); }
test.qbp
Description: Binary data
_______________________________________________ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development