Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
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 a
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
QString::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.
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 ?
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;
A workaround that you can try:
QString unicodeStr = "some Uniocode හාහාහා %1"; QString newStr = unicodeStr.arg(QString::fromUtf8(latinStr.data())); qDebug() << newStr;