Important: Please read the Qt Code of Conduct -

How to fix garbled text from QSqlQuery

  • Hello every one
    My OS is Ubuntu 16.04.
    The codec includes C C.UTF-8 en_US.utf8 zh_CN.utf8 zh_TW zh_TW.big5 zh_TW.utf8, and default setting is en_US.UTF-8

    The Server collation on my SQL Server is Chinese_Taiwan_Stroke_CI_AS.

    I installed Unixodbc and FreeTDS using code
    “sudo apt-get install unixodbc unixodbc-dev tdsodbc freetds-bin”

    Using isql to connect MSSQL server works okay and it didn’t display any garbled code as following picture


    However, it did not display any Chinese letters in “ “, when I tried to get the same data using Qt(QSqlQuerry). It only displayed English letters as picture.


    Here is part of the code I used

    QSqlQuery query("SELECT MES_DESC FROM BAS_MES ", db);
    qDebug() << "Result = " << query.value(0).toString() << endl;

    May I ask how I could solve this issue?
    I need to display Chinese letters in QT.

    Many Thanks in Advance.

  • Thanks

    I tryed to use the method, but it is not work for me.

    In my Qt, I can display the Chinese letters just using qDebug() as following picture

    but I don't know what's step wrong , I can't display the Chinese letters from the MSSQL server by Qt;

  • Hi, just guessing, but in your ~/.freetds.conf file, check that you have

    tds version = 8.0
    client charset = UTF-8

Log in to reply