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
Forum Updated to NodeBB v4.3 + New Features

How to fix garbled text from QSqlQuery

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.0k 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.
  • L Offline
    L Offline
    LeonSu
    wrote on 1 Feb 2018, 04:22 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.

    J 1 Reply Last reply 1 Feb 2018, 10:05
    0
    • L LeonSu
      1 Feb 2018, 04:22

      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.

      J Offline
      J Offline
      JonB
      wrote on 1 Feb 2018, 10:05 last edited by
      #2

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

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LeonSu
        wrote on 1 Feb 2018, 12:12 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
        • H Offline
          H Offline
          hskoglund
          wrote on 2 Feb 2018, 04:20 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

          1/4

          1 Feb 2018, 04:22

          • Login

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