Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to fix garbled text from QSqlQuery

How to fix garbled text from QSqlQuery

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • LeonSuL Offline
    LeonSuL Offline
    LeonSu
    wrote on last edited by
    #1

    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

    0_1517454994580_004.png

    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.

    0_1517455456896_003.png

    Here is part of the code I used

    QSqlQuery query("SELECT MES_DESC FROM BAS_MES ", db);
    if(query.isActive())
    {
    while(query.next()){
    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.

    JonBJ 1 Reply Last reply
    0
    • LeonSuL LeonSu

      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

      0_1517454994580_004.png

      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.

      0_1517455456896_003.png

      Here is part of the code I used

      QSqlQuery query("SELECT MES_DESC FROM BAS_MES ", db);
      if(query.isActive())
      {
      while(query.next()){
      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @LeonSu
      https://forum.qt.io/topic/57222/solved-printing-a-string-with-chinese-characters ?

      1 Reply Last reply
      0
      • LeonSuL Offline
        LeonSuL Offline
        LeonSu
        wrote on last edited by
        #3

        Thanks
        JonB

        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
        0_1517486192381_003.png

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

        1 Reply Last reply
        0
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #4

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

          tds version = 8.0
          client charset = UTF-8
          
          1 Reply Last reply
          4

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved