简体   繁体   中英

How to handle Korean character set between QT & Oracle

I'd like to use Oracle with ODBC.

I could get data from Oracle successfully. But Korean character is broken like ????. As all programmer said on internet forum, I tried to apply QTextCodec like below.

I tried EUC-KR and other codec names. 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.....

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.

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.

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 .

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM