Results 1 to 6 of 6

Thread: QString Unicode conversion

  1. #1
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default QString Unicode conversion

    How do I convert QString to unicode code.I need to support asian language. I am using asian language kepyboard input.

    So I have QString and I like to pass as std::string.
    SetUserName(std::string);
    QString strUser= "UserName";
    //I have tried following:-
    SetUserName(strUser.toUtf8().data());
    I have also tried this:-
    Qt Code:
    1. QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    2. QTextCodec::setCodecForCStrings(codec);
    To copy to clipboard, switch view to plain text mode 

    SetUserName(strUser.Ascii().data());

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QString Unicode conversion

    QString is internally unicode. You can access the characters individually as QChar's. I don't think std::string supports unicode?

  3. #3
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: QString Unicode conversion

    what if I use wstring. Wstring supports unicode.
    But still I don't get strUser.toStdWString().data())); to display right characters.

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QString Unicode conversion

    Have you considered toWCharArray?

  5. #5
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: QString Unicode conversion

    This is exact issue I am having with foreign language:- When I tried to do UTf8() it get breaks:-

    http://www.qtcentre.org/threads/1508...hlight=wchar_t


    Qt Code:
    1. QString memo_text=textEdit.toPlainText();
    2.  
    3. qDebug()<<memo_text; //Korean String value correct;
    4.  
    5. QByteArray textTemp(memo_text.toUtf8() );
    6.  
    7. qDebug()<<memo_text; //Korean String value incorrect; (weird characters) if I typed in korean
    8.  
    9. strcpy(memo_info->text , textTemp.data());
    10.  
    11. qDebug()<<memo_text; //Korean String value incorrect;
    To copy to clipboard, switch view to plain text mode 
    Last edited by user_mail07; 15th April 2010 at 20:04.

  6. #6
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: QString Unicode conversion

    I found a solution. Actually I was not doing fromUtf8() conversion back while reading the value of string in human readable form. ToUtf8() gived encoded value.

Similar Threads

  1. BSTR to QString Conversion
    By bismitapadhy in forum Qt Programming
    Replies: 9
    Last Post: 16th February 2012, 12:51
  2. char* to QString: conversion
    By abghosh in forum Qt Programming
    Replies: 9
    Last Post: 8th March 2010, 09:32
  3. Conversion of Unicode to Japanese
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 16th April 2008, 14:35
  4. qreal -> QString conversion
    By MarkoSan in forum Newbie
    Replies: 2
    Last Post: 13th April 2008, 14:37
  5. QString iso 8859-1 conversion
    By mattia in forum Newbie
    Replies: 11
    Last Post: 21st January 2008, 14:17

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.