Results 1 to 8 of 8

Thread: QTableView encoding problem

  1. #1
    Join Date
    Nov 2006
    Location
    Saudi Arabia
    Posts
    18
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb QTableView encoding problem

    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.

    also the same problem appear when i use this code:

    Qt Code:
    1. model->setTable("employees");
    2. model->setHeaderData(0,Qt::Horizontal,"الرقم التسلسلي"); // here i hava used an arabic text in the header
    3. model->select();
    4.  
    5. view->setModel(model);
    6. view->show();
    To copy to clipboard, switch view to plain text mode 

    can any one help??

    im using Linux and the charset for MySQL database is utf8.
    Last edited by SudaNix; 22nd February 2008 at 18:59.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView encoding problem

    Quote Originally Posted by SudaNix View Post
    i got un understandable text.
    Does Qt use a font that contains arabic characters? Are you sure that data in the database is correct?


    Quote Originally Posted by SudaNix View Post
    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().

  3. #3
    Join Date
    Nov 2006
    Location
    Saudi Arabia
    Posts
    18
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Re: QTableView encoding problem

    I think my qustion wasn't clear to be answered ..
    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

    thanx in advance

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTableView encoding problem

    Quote Originally Posted by SudaNix View Post
    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?

  5. #5
    Join Date
    Nov 2006
    Location
    Saudi Arabia
    Posts
    18
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView encoding problem

    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 :


    Qt Code:
    1. QSqlQuery query;
    2. query.exec("insert into EmployeeTable(ID,Name,Salary) values (1,'employee_name',300)");
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. QSqlQuery query;
    2. query.exec("insert into EmployeeTable(ID,Name,Salary) values (1,'احمد',300)");
    To copy to clipboard, switch view to plain text mode 


    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:

    Qt Code:
    1. model->setTable("EmployeeTable");
    2. model->select();
    3.  
    4. view->setModel(model);
    5. view->show();
    To copy to clipboard, switch view to plain text mode 

    hope u got me..

  6. #6
    Join Date
    Nov 2006
    Location
    Saudi Arabia
    Posts
    18
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: QTableView encoding problem

    jacek,,

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

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView encoding problem

    Quote Originally Posted by SudaNix View Post
    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.

  8. The following user says thank you to jacek for this useful post:

    SudaNix (26th February 2008)

  9. #8
    Join Date
    Nov 2006
    Location
    Saudi Arabia
    Posts
    18
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile Re: QTableView encoding problem

    the problem is solved with this line:

    Qt Code:
    1. QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    To copy to clipboard, switch view to plain text mode 

    thank u very mush jacek and wysota.

Similar Threads

  1. Problem with QTableView
    By BoneCollector in forum Qt Programming
    Replies: 5
    Last Post: 12th March 2008, 12:30
  2. Slow problem QTableView
    By skuda in forum Qt Programming
    Replies: 6
    Last Post: 26th February 2008, 12:19
  3. problem in printing QTableView
    By miguel_mark in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 08:19
  4. Problem: QThead and QTableview
    By ederbs in forum Qt Programming
    Replies: 5
    Last Post: 9th November 2007, 10:17
  5. qt and mysql encoding problem
    By ferasodh in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2007, 09:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.