PDA

View Full Version : QTableView encoding problem



SudaNix
22nd February 2008, 18:50
hello every body,

i have faced a problem in reading arabic data from MySQL database , that when i retrieved data ( with QSqlTableMode) and view it (with QTableView) i got un understandable text.:confused:

also the same problem appear when i use this code:



QSqlTableModel* model=new QSqlTableModel;
model->setTable("employees");
model->setHeaderData(0,Qt::Horizontal,"الرقم التسلسلي"); // here i hava used an arabic text in the header
model->select();

QTableView* view=new QTableView;
view->setModel(model);
view->show();

can any one help??

im using Linux and the charset for MySQL database is utf8.

jacek
25th February 2008, 12:35
i got un understandable text.:confused:
Does Qt use a font that contains arabic characters? Are you sure that data in the database is correct?



model->setHeaderData(0,Qt::Horizontal,"الرقم التسلسلي"); // here i hava used an arabic text in the header
By default Qt assumes that string literals are encoded in ISO-8859-1. Take a look at QTextCodec::setCodecForCStrings() and QTextCodec::setCodecForTr().

SudaNix
25th February 2008, 12:40
I think my qustion wasn't clear to be answered ..:o
so I'm gonna ask it again but in a clear language
...
I'm working in a Qt project with MySQL Database ... etc
I've stored data in Arabic in my database

when I populate my model with data from database and view it with QTableView
it appears in unknown language

so can I get any help over there plz:crying:

thanx in advance

wysota
25th February 2008, 12:57
I've stored data in Arabic in my database
How did you store the data? I mean... what exactly did you do and what application did you use?

SudaNix
25th February 2008, 13:33
firstly I'm using MySQL..
I've a table (EmployeeTable ) with fields ( ID, Name,Salary)

what I mean by ( I've stored data in Arabic in my database )
that I've typed some text in Arabic in Name field .. using this code :



QSqlQuery query;
query.exec("insert into EmployeeTable(ID,Name,Salary) values (1,'employee_name',300)");

but my employee_name in the above code is in Arabic Langauge like this:


QSqlQuery query;
query.exec("insert into EmployeeTable(ID,Name,Salary) values (1,'احمد',300)");


the problem is.. when I populate my model with data from database and view it with QTableView it appears in unknown language. see this Code:


QSqlTableModel* model=new QSqlTableModel;
model->setTable("EmployeeTable");
model->select();

QTableView* view=new QTableView;
view->setModel(model);
view->show();

hope u got me.. :confused:

SudaNix
25th February 2008, 13:36
jacek,,

I'll try it and feed you back ..
thanx for help

jacek
25th February 2008, 13:47
what I mean by ( I've stored data in Arabic in my database )
that I've typed some text in Arabic in Name field .. using this code :
....
QSqlQuery query;
query.exec("insert into EmployeeTable(ID,Name,Salary) values (1,'احمد',300)");
Then most likely the data in your database has bad encoding. Set encodings with setCodecForXxx() and insert the data again.

SudaNix
26th February 2008, 14:19
the problem is solved with this line:


QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("UTF-8"));

thank u very mush jacek and wysota. :rolleyes: