PDA

View Full Version : How to convert image data type to plain text and back ?



aircraftstories
12th April 2011, 19:04
Hello,

I have the following data :

"0x3C436F6E66696775726174696F6E5F46696C652074797065 3D22706572735F737570706F7274223E0D0A20203C6F626A5F 6964656E742076616C75653D223022202F3E0D0A20203C436F 6E66696775726174696F6E20747970653D22636C617373223E 0D0A202020203C734465736372697074696F6E20747970653D 2261747472223E417373656D626C79206C696E653120D180D1 83D181D181D0BAD0B8D0B93C2F734465736372697074696F6E 3E0D0A20203C2F436F6E66696775726174696F6E3E0D0A3C2F 436F6E66696775726174696F6E5F46696C653E"

which is stored in a "image" field of a MicroSoft SQL database.

This data is the binary representation of the plain text :

<Configuration_File type="pers_support">
<obj_ident value="0" />
<Configuration type="class">
<sDescription type="attr">Assembly line1 русский</sDescription>
</Configuration>
</Configuration_File>

obtained with : SELECT CONVERT(binary(8), data) AS ‘text to binary’

In Qt, I try to display (in a QTextBrowser) this data (enter in a QTextEdit) using :

text = QByteArray::fromHex(((ui->myQTextEdit->toPlainText()).remove(0,1)).toAscii());
ui->myQTextBrowser->setText(text);

but the result is :

<Configuration_File type="pers_support">
<obj_ident value="0" />
<Configuration type="class">
<sDescription type="attr">Assembly line1 русскÐ ¸ÃÂ¹</sDescription>
</Configuration>
</Configuration_File>

As you can see, the cyrillic word "русский" is not correctly decoded.

Any idea how to do that ?

Thanks

high_flyer
13th April 2011, 11:57
what happens if you use toUtf8 () ?

aircraftstories
13th April 2011, 12:13
what happens if you use toUtf8 () ?

Same result ....

aircraftstories
13th April 2011, 17:00
Solved by using :


{
QByteArray data;
data = ((ui->enterTextEdit->toPlainText()).remove(0,1) ).toUtf8();

QString strOK;
strOK = QString::fromUtf8(QByteArray::fromHex(data));
ui->resultTextBrowser->setText(strOK);
}

:)