[英]How to handle Korean character set between QT & Oracle
I'd like to use Oracle with ODBC. 我想将Oracle与ODBC一起使用。
I could get data from Oracle successfully. 我可以从Oracle成功获取数据。 But Korean character is broken like ????.
但是朝鲜语字符像????一样坏了。 As all programmer said on internet forum, I tried to apply
QTextCodec
like below. 正如所有程序员在Internet论坛上
QTextCodec
那样,我试图像下面那样应用QTextCodec
。
I tried EUC-KR
and other codec names. 我尝试了
EUC-KR
和其他编解码器名称。 But no change. 但是没有变化。
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QSqlQuery q("select * from temp", db);
q.setForwardOnly(true);
QString contect= "";
while(q.next())
{
QByteArray name = q.value(0).toByteArray();
QString age = q.value(1).toString();
contect = contect + codec->toUnicode(name);
ui.textEdit->setText(contect);
}
Oracle side info is..... Oracle补充信息是.....
NLS_CHARACTERSET : KO16MSWIN949
NLS_NCHAR_CHARACTERSET : AL16UTF16
NLS_LANG : KOREAN_KOREA.KO16MSWIN949
I'm developing with eclipse (on windows 7) and the default file text encoding is utf-8. 我正在使用Eclipse开发(在Windows 7上),默认文件文本编码为utf-8。
I'll appreciate it if you give me comment. 如果您给我评论,我将不胜感激。
Thanks. 谢谢。
I think you need to change the codec name as you need a codec from the Korean character set into UTF8. 我认为您需要更改编解码器名称,因为您需要将韩文字符集中的编解码器转换为 UTF8。
Try changing your code to: 尝试将代码更改为:
QTextCodec *codec = QTextCodec::codecForName("cp949");
As the Wikipedia page for Code page 949 mentions that it is non-standard Microsoft version of EUC-KR, you could also try EUC-KR
. 正如Wikipedia页面的Code页面949所提到的那样,它是EUC-KR的非标准Microsoft版本,您也可以尝试
EUC-KR
。
Try the following program to get the list of text codecs and aliases: 尝试以下程序获取文本编解码器和别名的列表:
test.cpp 测试文件
#include <QtCore>
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
const auto codecs = QTextCodec::availableCodecs();
for (auto it = codecs.begin(); it != codecs.end(); ++it)
{
const auto codec = QTextCodec::codecForName(*it);
qDebug() << codec->name() << codec->aliases();
}
return 0;
}
test.pro test.pro
QT += core
SOURCES=test.cpp
QMAKE_CXXFLAGS += -std=c++0x
Note that the program uses auto
for brevity, but this requires a C++11 compiler (tested on GCC 4.4). 请注意,为简洁起见,该程序使用了
auto
,但这需要C ++ 11编译器(已在GCC 4.4上进行了测试)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.