Hello,
I'm having troubles trying to convert a iso-8859-1 QString to something better, like an utf-8 QString.
A QByteArray (data) contains some mail headers (From, To, Subject, ...), and is downloaded from a server with a QTcpSocket. So, here is the code :
//data = QByteArray, contains the mail headers
liste_from
= QString::fromLatin1(data.
constData()).
trimmed().
split(' ');
//data = QByteArray, contains the mail headers
liste_from = QString::fromLatin1(data.constData()).trimmed().split(' ');
To copy to clipboard, switch view to plain text mode
Here I select the mail autor, the QString that I need to work with :
QString mail_autor
= liste_from.
operator[](1);
std::cout << "AUTOR : \t\t" << mail_autor.toStdString() << std::endl;
QString mail_autor = liste_from.operator[](1);
std::cout << "AUTOR : \t\t" << mail_autor.toStdString() << std::endl;
To copy to clipboard, switch view to plain text mode
Like mail is encoded in iso-8859-1 (RFC 2047), I get something like this :
=?iso-8859-1?Q?R=E9gis?=
=?iso-8859-1?Q?R=E9gis?=
To copy to clipboard, switch view to plain text mode
But I need to convert it, perhaps in utf-8, to get something like this :
Régis
Régis
To copy to clipboard, switch view to plain text mode
So I want to use some Qt functionalities, like QString::toUtf8() but nothing happens...
QString mail_autor
= liste_from.
operator[](1);
QByteArray mail_autor_converted
= mail_autor.
toUtf8();
std::cout << "AUTOR : \t\t" << mail_autor_converted.constData() << std::endl;
// Display : =?iso-8859-1?Q?R=E9gis?=
QString mail_autor = liste_from.operator[](1);
QByteArray mail_autor_converted = mail_autor.toUtf8();
std::cout << "AUTOR : \t\t" << mail_autor_converted.constData() << std::endl;
// Display : =?iso-8859-1?Q?R=E9gis?=
To copy to clipboard, switch view to plain text mode
I don't understand why the convertion isn't done.
Could you help me please ?
Bookmarks