View Full Version : QString Unicode conversion
user_mail07
15th April 2010, 16:56
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:-
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::setCodecForCStrings(codec);
SetUserName(strUser.Ascii().data());
squidge
15th April 2010, 17:46
QString is internally unicode. You can access the characters individually as QChar's. I don't think std::string supports unicode?
user_mail07
15th April 2010, 18:36
what if I use wstring. Wstring supports unicode.
But still I don't get strUser.toStdWString().data())); to display right characters.
squidge
15th April 2010, 19:12
Have you considered toWCharArray?
user_mail07
15th April 2010, 19:55
This is exact issue I am having with foreign language:- When I tried to do UTf8() it get breaks:-
http://www.qtcentre.org/threads/15080-convert-QString-to-QByteArray?highlight=wchar_t
QString memo_text=textEdit.toPlainText();
qDebug()<<memo_text; //Korean String value correct;
QByteArray textTemp(memo_text.toUtf8() );
qDebug()<<memo_text; //Korean String value incorrect; (weird characters) if I typed in korean
strcpy(memo_info->text , textTemp.data());
qDebug()<<memo_text; //Korean String value incorrect;
user_mail07
15th April 2010, 22:16
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.