Important: Please read the Qt Code of Conduct -

Chinese with Qt

  • hello
    I'm working on a Qt based project which should do the following:

    • store information in a sqllite database

    • transfer it using xmlrpc

    • display it in a gui

    This is all working with "normal" characters, but I'm reall confused how to proceed with chinese...
    I do not know any chinese nor anything about the structure of the language, and my knowledge
    regarding different kinds of encodings is limited.

    Any suggestions how to proceed and what should be acknowledged? I don't even know where to start...

  • Qt provides full Unicode support. So as long as you use QString (it uses Unicode encoded as UTF-16 internally) for your strings, Chinese or whatever characters are no problem at all! Also all GUI widgets of Qt support Unicode, so just set the text from a QString, e.g. QLabel::setText(myStr) where myStr is a QString, and you should be fine.

    Only remaining problem is to get the text from your DB into a QString properly. If the data in your DB is encoded in UTF-8, for example, you can construct a proper QString with QString::fromUtf8(...). If the text in the DB is encoded in some "regional" 8-Bit Codepage, you can convert it to a QString and thus UTF-16/Unicode by using QTextCodec::toUnicode(). In the latter case you will have to know the proper Codepage beforehand, of course.

    (For Chinese text the "Big 5" Codepage is a good candidate. Unicode is always preferable though!)

  • Hi ThaRez,

    You should tell us which encoding your used in

    • your sqlite database
    • when transfer in xmprpc
    • your remote gui

    Three encodings widely used in Chinese:

    • UTF-8
    • GB18030 (also known as GBK/GB2312), China Mainland and Singapore
    • Big5, China Taiwan and Hong Kong

Log in to reply