Results 1 to 6 of 6

Thread: Mysql and Arabic encoding issue

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

    Default Mysql and Arabic encoding issue

    Hello everyone

    I have a problem with MySQL and Arabic characters

    I use the following line of codes to insert a record to a table


    Qt Code:
    1. QString name ="يزن";
    2.  
    3. query.prepare("INSERT INTO stock (name, num) VALUES (:name, 10)" );
    4. query.bindValue(":name", name);
    5. query.exec();
    To copy to clipboard, switch view to plain text mode 

    the record is entered successfully, although the name variable is changed to this 'Ã*Òä', as shown in the mysql browser

    when I try to retrieve the record from the database, I get ??? displayed on the QLabel object

    What should I do so that the value I enter to the database remains the same, i.e. يزن, and when I retrieve it, also displays correctly

    Thanks alot for your help

  2. #2
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Mysql and Arabic encoding issue

    Change charset using QSqlDatabase::setConnectOptions() during connection establishment to arabic. Should work.
    -- Tanuki

    per cauda vel vaculus cauda

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

    Default Re: Mysql and Arabic encoding issue

    Hey Tanuki

    Thanks for your reply

    do you know the exact format for the mysql connection string option so that I can set it to Arabic charset (ISO8859_6)

    I tried the following,
    Qt Code:
    1. m_database.setConnectOptions("SET NAMES 'UTF8'");
    To copy to clipboard, switch view to plain text mode 

    but I get the following error

    QMYSQLDriver:: open: Unknown connect option 'SET NAMES 'UTF8''

    Thanks in advance

  4. #4
    Join Date
    Mar 2006
    Posts
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Mysql and Arabic encoding issue

    If UTF-8 encoding is used in the code source .
    Try
    Qt Code:
    1. QString name = QString::fromUtf8("يزن");
    To copy to clipboard, switch view to plain text mode 
    By default QString assumes that such strings have ASCII encoding.

    QString ctor
    setCodecForCString

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

    Default Re: Mysql and Arabic encoding issue

    Thanks all

    its solved using the following line

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

    and then, I use the same code as before

    Qt Code:
    1. QString name ="يزن";
    2.  
    3. query.prepare("INSERT INTO stock (name, num) VALUES (:name, 10)" );
    4. query.bindValue(":name", name);
    5. query.exec();
    To copy to clipboard, switch view to plain text mode 

    and the value is saved as يزن and retrieved as يزن

    Thanks again

  6. #6
    Join Date
    Mar 2011
    Location
    Copper Mountain Colorado
    Posts
    1

    Default Re: Mysql and Arabic encoding issue

    My advice is to use UTF-8 it's universal encoding. And run SET NAMES 'utf8'; after connecting to DB:

    Qt Code:
    1. $link = mysql_connect('host', 'user', 'password');
    2. mysql_query('SET NAMES utf8', $link);
    To copy to clipboard, switch view to plain text mode 
    Make sure you back up the database
    Last edited by coloradorockies; 23rd March 2011 at 15:49. Reason: missing [code] tags

Similar Threads

  1. Replies: 5
    Last Post: 25th September 2009, 14:03
  2. Fonts opensource for chinese and arabic
    By recalcati in forum Qt Programming
    Replies: 0
    Last Post: 30th April 2008, 10:06
  3. qt and mysql encoding problem
    By ferasodh in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2007, 09:48
  4. QT/mySQL deployment issue
    By smtgra011 in forum Installation and Deployment
    Replies: 4
    Last Post: 1st July 2007, 20:31
  5. Mysql LD_LIBRARY_PATH Issue
    By Think_Positive in forum Installation and Deployment
    Replies: 3
    Last Post: 13th February 2007, 19: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.