PDA

View Full Version : SQLite reading Chinese strings issue



yazwas
5th April 2011, 11:27
Good day

I have a sqlite table that has a simplified Chinese column, and I want to preview that table in QSqlTableModel
I was able to print Chinese characters to the label using the following code

QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("GB2312"));
QString a= "T氓颅鈥斆ヂ嘎";
ui->label->setText(a);


and it shows OK, so I think the issue is when reading from the db. I've tried SQLite administrator tool and it shows the table with the Chinese entries OK

What do you think a solution to this issue is?

Thanks!

yazwas
6th April 2011, 08:37
I fixed this by using the following


QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("GB18030")); //gb18030 was the encoding of the data.

//then using a query to retrieve the data, and display like below
QString str = query.value(0).toString().toUtf8(); //this would show a correct encoding of the data!