Results 1 to 6 of 6

Thread: MySQL UTF-8 encoding issue

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: MySQL UTF-8 encoding issue

    why do you convert your result to an byte array? there you skip the informations. Just do
    Qt Code:
    1. bool ret = query.exec("select name_searchword from searchword where id_company = 1125");
    2. while(query.next())
    3. {
    4. QString st = query.value(0).toString();
    5. qDebug() << "Str is :" << st;
    6. }
    To copy to clipboard, switch view to plain text mode 
    and all should work fine.

  2. #2
    Join Date
    Jul 2009
    Location
    Jordan, and UAE
    Posts
    55
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    3

    Default Re: MySQL UTF-8 encoding issue

    Hey Lykurg

    I tried this, but it gave me the following result
    Str is : "?¯?¨U‰"

    thankx, but what do you think is the reason?

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: MySQL UTF-8 encoding issue

    Are you sure that your data in the database is encoded in utf8 correctly? Do you use any encoding function in php before printing it?

    You can try to set utf8 explicitly after establishing the connection to your database using:
    sql Code:
    1. SET NAMES 'utf8';
    2. SET CHARACTER SET 'utf8';
    To copy to clipboard, switch view to plain text mode 

    (Not sure right now if it has to be utf8 or utf-8...)

  4. #4
    Join Date
    Jul 2009
    Location
    Jordan, and UAE
    Posts
    55
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    3

    Default Re: MySQL UTF-8 encoding issue

    I'm sure of the text is encoded correctly in UTF8, in PHP it shows if I use the following line at the beginning of the page
    <?php header("Content-type: text/html; charset=utf-8");

    and then I use code directly, and everything works out fine.

    This is how my Qt code looks like, and I still dont have the correct result, if you can see something that I'm missing, please point it out to me.
    Thanks

    Qt Code:
    1. QSqlQuery query(m_masterDatabase);
    2.  
    3. bool ret = query.exec("SET NAMES 'utf8'");
    4. if(ret)
    5. qDebug() << "true1";
    6. else
    7. qDebug() << query.lastError().text();
    8.  
    9. ret = query.exec("SET CHARACTER SET 'utf8'");
    10. if(ret)
    11. qDebug() << "true2";
    12. else
    13. qDebug() << query.lastError().text();
    14.  
    15. ret = query.exec("select name_searchword from searchword where id_company = 1125");
    16. while(query.next())
    17. {
    18. QString st = query.value(0).toString();
    19. qDebug() << "Str is :" << st;
    20. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: MySQL UTF-8 encoding issue

    Well right now it seems to me, that your database in not right encoded. Your Qt is fine.

    You could make a test: insert a new row to your database by using Qt. Make sure all is utf8. (use QString::fromUtf8() etc.) then querry that row and see if it is displayed correct.

Similar Threads

  1. Mysql and Arabic encoding issue
    By yazwas in forum Qt Programming
    Replies: 5
    Last Post: 23rd March 2011, 16:43
  2. Replies: 5
    Last Post: 25th September 2009, 15:03
  3. qt and mysql encoding problem
    By ferasodh in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2007, 10:48
  4. QT/mySQL deployment issue
    By smtgra011 in forum Installation and Deployment
    Replies: 4
    Last Post: 1st July 2007, 21:31
  5. Mysql LD_LIBRARY_PATH Issue
    By Think_Positive in forum Installation and Deployment
    Replies: 3
    Last Post: 13th February 2007, 20:16

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
  •  
Qt is a trademark of The Qt Company.