Results 1 to 4 of 4

Thread: How to convert image data type to plain text and back ?

  1. #1
    Join Date
    Apr 2011
    Posts
    8
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default How to convert image data type to plain text and back ?

    Hello,

    I have the following data :

    "0x3C436F6E66696775726174696F6E5F46696C65207479706 53D22706572735F737570706F7274223E0D0A20203C6F626A5 F6964656E742076616C75653D223022202F3E0D0A20203C436 F6E66696775726174696F6E20747970653D22636C617373223 E0D0A202020203C734465736372697074696F6E20747970653 D2261747472223E417373656D626C79206C696E653120D180D 183D181D181D0BAD0B8D0B93C2F734465736372697074696F6 E3E0D0A20203C2F436F6E66696775726174696F6E3E0D0A3C2 F436F6E66696775726174696F6E5F46696C653E"

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to convert image data type to plain text and back ?

    what happens if you use toUtf8 () ?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2011
    Posts
    8
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to convert image data type to plain text and back ?

    Quote Originally Posted by high_flyer View Post
    what happens if you use toUtf8 () ?
    Same result ....

  4. #4
    Join Date
    Apr 2011
    Posts
    8
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to convert image data type to plain text and back ?

    Solved by using :
    Qt Code:
    1. {
    2. QByteArray data;
    3. data = ((ui->enterTextEdit->toPlainText()).remove(0,1) ).toUtf8();
    4.  
    5. QString strOK;
    6. strOK = QString::fromUtf8(QByteArray::fromHex(data));
    7. ui->resultTextBrowser->setText(strOK);
    8. }
    To copy to clipboard, switch view to plain text mode 

    Last edited by high_flyer; 13th April 2011 at 16:14. Reason: code tags

Similar Threads

  1. Display an image to a plain QWidget
    By franco.amato in forum Qt Programming
    Replies: 4
    Last Post: 19th March 2012, 09:07
  2. convert decimal seconds to QDateTime and back
    By mcarter in forum Qt Programming
    Replies: 2
    Last Post: 18th March 2010, 12:06
  3. Convert between a custom data type wrapped in a QVariant
    By darkadept in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 09:07
  4. Replies: 6
    Last Post: 4th February 2009, 07:46
  5. QTextEdit + paste rich text as plain text only
    By Yong in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2008, 16:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.