View Full Version : UNICODE UTF-8 String in QT + Eclipse?????
thaihoangluu
29th December 2011, 09:03
I use Eclipse IDE for C/C++ & QT integration plug-in , but I can not write in Unicode font ?
How to resolve ? Thank every body.
Example: I write : "Chà o tất cả các bạn!" but It show in program: "Chà o t?t c? các b?n"
kunashir
29th December 2011, 09:23
Hello.
Are You create console application? In IDE displays all right?
thaihoangluu
29th December 2011, 09:27
HÃ*c.
I use QpushBotton,... not display utf - 8 :(
kunashir
29th December 2011, 09:37
Ok.
I have done so:
1. Check code page in Eclipse, maybe it different from system code page.
if code page is ok, try to use next:
QTextCodec *incodec = QTextCodec::codecForName ("CP1251"); // change "CP1251" to our code page
QTextCodec::setCodecForTr(incodec);
//in module with pushbutton
QPushButton *button = new QPushButton( tr("Chà o tất cả các bạn!"), this);
stampede
29th December 2011, 11:11
You can display your text without changing codec:
#include <QApplication>
#include <QLabel>
int main(int argc, char **argv) {
QApplication app(argc, argv);
QLabel label(QString::fromWCharArray(L"Chà o tất cả các bạn!"));
label.show();
return app.exec();
}
Edit:
this is not really good, because of dynamic translations, but this should work ok:
#include <QApplication>
#include <QLabel>
int main(int argc, char **argv) {
QApplication app(argc, argv);
QLabel label(Qbject::trUtf8("Chà o tất cả các bạn!"));
label.show();
return app.exec();
}
edit 2:
try to call QTextCodec::setCodecForTr(QTextCodec::codecForName ("UTF-8")); in your main() function, then you should be able to use regular tr("") method:
#include <QApplication>
#include <QLabel>
int main(int argc, char **argv) {
QApplication app(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName ("UTF-8"));
QLabel label(Qbject::tr("Chà o tất cả các bạn!"));
label.show();
return app.exec();
}
thaihoangluu
30th December 2011, 01:27
Ok.
I have done so:
1. Check code page in Eclipse, maybe it different from system code page.
if code page is ok, try to use next:
QTextCodec *incodec = QTextCodec::codecForName ("CP1251"); // change "CP1251" to our code page
QTextCodec::setCodecForTr(incodec);
//in module with pushbutton
QPushButton *button = new QPushButton( tr("Chà o tất cả các bạn!"), this);
It's code Error :(
You can display your text without changing codec:
#include <QApplication>
#include <QLabel>
int main(int argc, char **argv) {
QApplication app(argc, argv);
QLabel label(QString::fromWCharArray(L"Chà o tất cả các bạn!"));
label.show();
return app.exec();
}
Edit:
this is not really good, because of dynamic translations, but this should work ok:
#include <QApplication>
#include <QLabel>
int main(int argc, char **argv) {
QApplication app(argc, argv);
QLabel label(Qbject::trUtf8("Chà o tất cả các bạn!"));
label.show();
return app.exec();
}
edit 2:
try to call QTextCodec::setCodecForTr(QTextCodec::codecForName ("UTF-8")); in your main() function, then you should be able to use regular tr("") method:
#include <QApplication>
#include <QLabel>
int main(int argc, char **argv) {
QApplication app(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName ("UTF-8"));
QLabel label(Qbject::tr("Chà o tất cả các bạn!"));
label.show();
return app.exec();
}
The Fisrt code it's Work, but the second and third : Error :(
7215
Thank everybody for watching.
kunashir
30th December 2011, 05:06
Your have error in code:
QLablel lable (Qbject::tr(...));
//rigth path this
QLablel lable (QObject::tr(...));
You missed "O" in QObject.
thaihoangluu
31st December 2011, 01:14
Your have error in code:
QLablel lable (Qbject::tr(...));
//rigth path this
QLablel lable (QObject::tr(...));
You missed "O" in QObject.
Oh.Sorry kunashir , I don't see :D
THANK EVERYBODY
My problem is solved.
Cheers.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.