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. About chinese characteristics error in ODBC way
QtWS25 Last Chance

About chinese characteristics error in ODBC way

Scheduled Pinned Locked Moved Unsolved General and Desktop
chineseodbcutf
6 Posts 3 Posters 2.1k Views
  • 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.
  • M Offline
    M Offline
    MartinChan
    wrote on last edited by
    #1

    First want to thank @mrjj again for the help of odbc before.

    After install the new qt and office finally i succeed in load in the excel file through odbc.

    However,when i want to load the text of each cell,it only return "?????" like this.(Excel content is like this.)

    I guess it's about the compatibility of Chinese characteristics.

    Code:

    #include <QCoreApplication>
    #include <QSql>
    #include <QSqlDatabase>
    #include <QSqlQuery>
    #include <QVariant>
    #include <QDebug>
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
        QSqlQuery query;
            db.setDatabaseName("Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=D:\\grade.xls;DefaultDir=c:\\;");
            if (db.open())
            {
    
                bool flag = query.exec(QStringLiteral("select * from [Sheet1$]"));
                while (query.next()) {
                    QString title = query.value(0).toString();
                    QString author = query.value(1).toString();
                    qDebug()<<title<<" "<<author;
                    //QMessageBox::critical(0, title,author);
                }
         }
        return a.exec();
    }
    
    1 Reply Last reply
    1
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      hi
      maybe a silly question, but what is the content of title /author if
      you view it in debugger?

      M 2 Replies Last reply
      0
      • mrjjM mrjj

        hi
        maybe a silly question, but what is the content of title /author if
        you view it in debugger?

        M Offline
        M Offline
        MartinChan
        wrote on last edited by
        #3

        @mrjj Here is the debugger pic,and you can see that it has been an messy code in debugger.

        By the way,it seems that Qt has a bad support for Chinese characters for a long time,it disturbs developers in China a lot and I really want Qt could solve it in the recent future.

        I saw some posts on the Internet said if the excel file has the Chinese characters, you'd better use QAxObject to call the ADO way to connect to access file or excel file.I will try it tomorrow.
        Good night.

        1 Reply Last reply
        0
        • mrjjM mrjj

          hi
          maybe a silly question, but what is the content of title /author if
          you view it in debugger?

          M Offline
          M Offline
          MartinChan
          wrote on last edited by MartinChan
          #4

          @mrjj Suddenly i see some post on the Internet said it may do a little change in qsql_odbc.cpp(Line 2300,change

          QString fieldVal = qGetStringData(hStmt, 2, -1, false);
          
          to
          
          QString fieldVal = qGetStringData(hStmt, 2, -1, true);
          

          So,here is the new question,I simply do the qmake and nmake,and it seems not work(and this time its config process doesn't last too long),I doubt that I should deleted the driver I installed before and then I can config again. So,how could I deleted the driver I configure before??

          thx

          @Leo-Z maybe you can supply some help in this question

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MartinChan
            wrote on last edited by
            #5

            About the Chinese question,you can solve it through QAxObject like this way.

            I will not change the unsolved situation of this question until Qt solved the ODBC Chinese characteristic...

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Did you already checked the bug report system to see if it's something known ? If not, can you open a new report with a minimal compilable example that shows this behavior ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

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