About chinese characteristics error in ODBC way
-
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(); }
-
hi
maybe a silly question, but what is the content of title /author if
you view it in debugger? -
@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. -
@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
-
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...
-
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 ?