Results 1 to 2 of 2

Thread: Writing raw bytes as text?

  1. #1
    Join Date
    Apr 2009
    Posts
    63
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Writing raw bytes as text?

    I have a file that I wrote bytes to (MyFile below)... these bytes were actually just xml text originally, but were written as bytes or a bytearray. My question is how would I take those raw bytes and write them as the xml text they represent to a different file?

    Qt Code:
    1. QFile fileReadIn ("MyFile");
    2. if (fileReadIn.open( QFile::ReadOnly ))
    3. {
    4. QFile testFile( "Result.xml" );
    5. testFile.open( QIODevice::WriteOnly );
    6. testFile.write(fileReadIn.readAll());
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 18th May 2009 at 15:23. Reason: missing [code] tags

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Writing raw bytes as text?

    That depends on the contents of your input file.
    Could you please clarify what you mean by "written as bytes or a bytearray"?

    Basically: You need to read them "inverse to the way you wrote them", convert that bytearray into a QString and then write that (in the desired encoding) to your output file.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Match the text beetween two string
    By dreamer in forum Qt Programming
    Replies: 4
    Last Post: 20th May 2008, 14:48
  3. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 13:51
  4. problem in writing text with QFile
    By wei243 in forum Qt Programming
    Replies: 5
    Last Post: 6th March 2007, 14:26
  5. Writing Text on a Rectangle!!!
    By Kapil in forum Qt Programming
    Replies: 3
    Last Post: 17th May 2006, 10:23

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.