[Development] Why we *have to* remove codecFor... ?
1+1=2
dbzhang800 at gmail.com
Sun Apr 22 23:47:10 CEST 2012
Hi Loden,
The source code you provided if not cross-platform even under Qt4.
Under Windows platform, source file is save using encoding "GBK" while
under linux platform it saved as "UTF-8"
which means you are using two sets of source code for two platforms.
In addition, these are two errors(mistakes) in your source code.
1. Q_WS_WIN should be changed to Q_OS_WIN even you are using Qt4
2. You should not call setCodecForLocale() in such cases, no mater
you are using Qt4 or Qt5.
Debao
2012/4/22 Loaden <loaden at gmail.com>:
> After test, I can sure this code can works well on Windows 32bit + MSVC2010
> or Linux 64bit + GCC4.6.2 with Qt4.
> But can't work with Qt5.
> Please give me a sulution about this case.
>>
>>
>> #include <QApplication>
>> #include <QLabel>
>> #include <QTextCodec>
>> #include <QTextStream>
>> #include <QDebug>
>>
>> int main(int argc, char *argv[])
>> {
>> #ifdef Q_WS_WIN
>>
>>
>> QTextCodec *codec = QTextCodec::codecForName("GBK");
>> #else
>> QTextCodec *codec = QTextCodec::codecForName("UTF-8");
>> #endif
>>
>> QTextCodec::setCodecForLocale(codec);
>> #if QT_VERSION < 0x050000
>> QTextCodec::setCodecForCStrings(codec);
>> QTextCodec::setCodecForTr(codec);
>> #endif
>> QApplication app(argc, argv);
>> QString str = "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();
>> }
>
More information about the Development
mailing list