Show QLatin1String concat of Unicode QString in a single string
-
I know the title is a bit confusing, even I don't know how to summarize it. Here is the issue.
I have two strings, one is an Extended ASCII (can be represented using
QLatin1String
) and a Unicode String (can be represented by aQString
).I am combining them using
QString::arg()
method as below.QLatin1String latinStr = "Adiós"; QString unicodeStr = "some Uniocode හාහාහා %1"; QString newStr = unicodeStr.arg(latinStr);
Now this newStr has my concatenated string. If I print newStr, it prints "?" for the extended ASCII. If I convert the
newStr
to aQLatin1String
usingQString::fromLatin1()
, the unicode part shows in a weird way.Is there any way to solve this?
PS : I already have posted this in StackOverflow, but haven't got any solution yet.
(http://stackoverflow.com/questions/32002281/show-qlatin1string-concat-of-unicode-qstring-in-a-single-string) -
Hi and welcome to devnet,
Are you by any chance using Qt 5.5 ?
-
No, I'm using Qt 5.2.
Is there any workaround in Qt 5.5 ?Thanks.
-
Sorry, I have mixed your problem with another one. In any case isn't ó unicode rather than Latin1 ?
-
@SGaist It can be either Unicode or Extended ASCIIm depending on the encoding used when creating the character. For the moment, let's assume that it is Extended ASCII.
If so, what can be the remedy?
-
I wouldn't assume that.
QLatin1String latinStr("Adiós"); qDebug() << latinStr << newStr;
Gives:
"Adi\u00C3\u00B3s"
A workaround that you can try:
QString unicodeStr = "some Uniocode හාහාහා %1"; QString newStr = unicodeStr.arg(QString::fromUtf8(latinStr.data())); qDebug() << newStr;