Qt and MySQL C API
-
Hi, I'm using MySQL C connector to connect to my database. My tables are in UTF-8 format. When I try to read my data I haven't right output. Here is my code:
@my_ulonglong rows;
mysql_query(&conn, command.toAscii().data());
res = mysql_store_result(&conn);
QList<QList<QString> > vysledok;
int i;
QList<QString> riadok;
while ((row = mysql_fetch_row(res)) != NULL) {
riadok.clear();
for (i = 0; i < rows; i++) {
QString temp;
temp = QString::fromUtf8(row[i]);
qDebug() << temp;
}
}
mysql_free_result(res);
return vysledok;@
And my screen with debug error is here:
!http://mksoft.marconet.sk/mysql_debug.jpg(Output)!My application output is:
@Debugging starts
"1"
"Administrator"
"Website administrator"
"??01??0????????0??0??0?+1?2"
Debugging has finished@ -
I can't see why you don't use Qt MySQL plugin...
-
I have some problems with compilation of plugin
-
What problems? I had problems too, but finally had success on Windows using MinGW 4.6 and MySQL 5.1.3 libraries.
On Linux you don't need to compile. They already exist some packages ;)
-
While compilation I had problems with MySQL lib source, On Linux I haven't problems, but now I'm on W7. Finally, yesterday I managed to compile QMYSQL module with Qt 4.8.1, MySQL C Connector 6.0.2 and with MSVC 2010
-
Hi Sibyx,
You can try this code:
mysql_init(&mysql);
mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, "utf8");
mysql_options(&mysql, MYSQL_INIT_COMMAND, "SET NAMES utf8");mysql_real_connect(&mysql,CTH_SERVER,CTH_USER,CTH_PASSWORD,CTH_DB_IN,0,0,0));
:)