Results 1 to 4 of 4

Thread: QDataStream writing wrong values

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QDataStream writing wrong values

    Please let me know how to address this problem
    There is no problem. QDataStream is outputting exactly what you asked it to. You have a 32-bit unsigned integer with the value 54 and you have asked for output in LittleEndian order. The integer is 4 bytes 0x00000036, and QDataStream outputs them in reverse order. You get 4 bytes in the file, the first is 54 decimal (0x36) followed by 3 zero bytes. Treated as text this is equivalent to the C string "6".

    Qt Code:
    1. const int num = 54;
    2.  
    3. QFile out("out.txt");
    4. if (out.open(QIODevice::WriteOnly) {
    5. QTextStream s(&out);
    6. s << num;
    7. }
    To copy to clipboard, switch view to plain text mode 
    Also look at QString::number(), QByteArray::number() etc.

  2. The following user says thank you to ChrisW67 for this useful post:

    alok9871 (21st March 2013)

Similar Threads

  1. qbytearray qdatastream qfile writing/reading
    By pekal in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2012, 21:51
  2. How to convert string hex values to its real binary values?
    By AttilaPethe in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2012, 22:47
  3. QextSerialPort reading error: wrong values
    By Lawand in forum Qt Programming
    Replies: 9
    Last Post: 6th May 2009, 19:29
  4. QDataStream
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 23rd August 2006, 14:40
  5. QDataStream
    By frankoz in forum Qt Programming
    Replies: 1
    Last Post: 1st March 2006, 07:18

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.