[Interest] Detecting QString encoding errors

BAILLY Yves Yves.Bailly at hexagonmetrology.com
Mon Apr 11 09:59:15 CEST 2016


Greetings all,

Is it possible to detect errors while encoding a QString from char*?

Here's the case: I get a string as a char* form an external library (on which I don't have any control).
This string can use either UTF8 encoding, or "local8bit" encoding - thus may vary from a user to the other.

What I basically need is to be table to write something like this:
char const* src = ...;
bool encoding_failed = false;
QString qs = QString::fromUtf8(src, &encoding_failed);
if ( encoding_failed )
{
  qs = QString::fromLocal8Bit(src);
}

I looked at the docs for QString and QTextCodec, but I couldn't find any error support.

Is there any (portable) way of achieving this?

Thanks in advance for any hint.

--
Yves Bailly
Software developer


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160411/6d7220a4/attachment.html>


More information about the Interest mailing list