PDA

View Full Version : Convert euro sign from QString to UTF-8



Spiderghost
22nd March 2013, 15:27
Hi all,

from a cross platform project i had to convert the euro symbol to store it to an UTF-8 coded database. To make the problem more complex; database requests are made via LUA.

The euro symbol is entered by a QTextEdit and i do some function calls like the following lines:


...
// Function called from LUA to convert Data to be stored
static
string StrToUTF8 (
const char* Source
)
{
string result;
if ( Source && Source [ 0 ] )
{
QString converter ( QString::fromLocal8Bit ( Source ) );
result = converter.toUtf8 ().constData ();
}
return result;
}

...
QString text (textedit -> text ());
qDebug () << "FromEdit:" << text << "," << text.toLocal8Bit ().constData ();
// Call a lua function
WriteToDatabase (text.toLocal8Bit ().constData ());
...

So the UTF-8 value for euro symbol should be E2 82 AC. But i alway got E2 80.

Any suggestions what i am doing wrong?

Platform is Windows 7, Windows XP and embedded Linux.

BTW: reading UTF-8 by calling QString::fromUtf8 () works fine.

Kind regards

Spiderghost

Added after 17 minutes:

Sometimes it helps to explain some part of code ... after writing this part and comparing it to the original code, i saw at once that the part "QString::fromLocal8Bit ( Source )" was missing ...

Thank you for listing. The problem was sitting in front of my screen ... ;)

Kind regards

Spiderghost