[Development] qPrintable encoding issues
Matthew Woehlke
mw_triad at users.sourceforge.net
Fri Feb 28 17:30:57 CET 2014
On 2014-02-28 04:16, Koehne Kai wrote:
>> [...]
>> What about adding e.g. qRawUtf8() which would do like qPrintable but
>> toUtf8() instead of toLocal8Bit()?
>
> I've been pondering with this something similar too, since
>
> qDebug("%s", string.toUtf8().constData());
>
> isn't really short and crisp ... But I just found out that there's a
> more elegant way: QString::snprintf and therefore also qDebug() and
> friends support the %ls placeholder, so you can write
>
> qDebug("%ls", string.utf16());
This doesn't help if I am doing e.g.:
MyClass foo;
QString msg;
qDebug() << "literal" << foo << "literal"
<< some_value << qPrintable(msg);
I think a solution that can be used with QDebug::operator<< is needed.
>> (If you don't otherwise care about doing conversions to local-8-bit, couldn't
>> you also set the string locale to UTF-8?)
>
> Sorry, I didn't get this question / proposal :)
I would assume that setting the current Qt locale to UTF-8 results in
toLocal8Bit being a synonym for toUtf8. (Note: I'm talking about
*applications* adding a call to do this. They would have to evaluate if
doing so is likely to break anything else.)
--
Matthew
More information about the Development
mailing list