Results 1 to 4 of 4

Thread: QByteArray appending quint32 not working

  1. #1

    Default QByteArray appending quint32 not working

    I have the following code:

    Qt Code:
    1. quint32 num = 17;
    2.  
    3. ba.append(num);
    4.  
    5. qDebug() << "BA Size: " << ba.size();
    To copy to clipboard, switch view to plain text mode 

    I expect the output to be 4, since the a quint32 is comprised of 4 bytes. However, the output is 1 byte.

    So, my question is, how do I append a quint32 number?

  2. #2

    Default Re: QByteArray appending quint32 not working

    Answer for anyone else in the future:

    Qt Code:
    1. quint32 num = 17;
    2. QDataStream ds(&ba, QIODevice::WriteOnly);
    3. ds << num;
    4. qDebug() << "BA Size: " << ba.size();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2010
    Location
    Finland
    Posts
    7
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray appending quint32 not working

    I suggest tat you try method setNum andse if it works better.

  4. #4

    Default Re: QByteArray appending quint32 not working

    The datastream method above works great, but it is a little bulky.

    The problem with setNum() is that it converts the number into a string.

Similar Threads

  1. Replies: 9
    Last Post: 25th July 2009, 13:27
  2. Appending text to a file
    By janus in forum General Programming
    Replies: 8
    Last Post: 25th March 2009, 11:23
  3. data is not appending to the file
    By sudheer in forum Qt Tools
    Replies: 2
    Last Post: 3rd April 2008, 12:39
  4. appending QByteArray with variable.
    By jjbabu in forum Qt Programming
    Replies: 3
    Last Post: 18th October 2007, 08:24
  5. append slots not... appending?
    By Slip Nine in forum Newbie
    Replies: 1
    Last Post: 26th May 2006, 08:40

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.