Results 1 to 3 of 3

Thread: how QDataStream and QByteArray related

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    38
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Question how QDataStream and QByteArray related

    I am not sure why every one has to use QDataStream with QByteArray ??
    why???

    please have a look the code
    Qt Code:
    1. QBuffer buffer;
    2. QImageWriter writer(&buffer, "PNG");
    3. writer.write( randomImage() );
    4. [COLOR="red"]QByteArray data;[/COLOR]
    5. QDataStream stream( &data, QIODevice::WriteOnly );
    6. stream << (quint32)buffer.data().size();
    7. data.append( buffer.data() );
    8. socket.write( data );
    To copy to clipboard, switch view to plain text mode 
    this code is to send a picture.
    for same purpose:
    Qt Code:
    1. QBuffer buffer;
    2. QImageWriter writer(&buffer, "PNG");
    3. writer.write( randomImage() );
    4. QByteArray data;
    5. QDataStream stream(&socket);
    6. stream << (quint32)buffer.data().size();
    7. stream << buffer.data();
    To copy to clipboard, switch view to plain text mode 
    works good as well.

    1 i am so confused, what is purpose of having QByteArray in first code???

    2 and in second code i don't even need socket.write( ) to send data... why>?

    3 in first code, dose "stream << (quint32)buffer.data().size();" means write the size into (QByteArray) data?
    Last edited by dognzhe; 7th May 2009 at 06:59.

Similar Threads

  1. QDataStream and QByteArray issue
    By sepehr in forum Qt Programming
    Replies: 13
    Last Post: 2nd April 2021, 16:41
  2. Streaming QImage (QByteArray, QDataStream, QBuffer)
    By knarz in forum Qt Programming
    Replies: 5
    Last Post: 17th January 2009, 22:05
  3. QByteArray problem
    By Misenko in forum Qt Programming
    Replies: 17
    Last Post: 4th October 2008, 21:53
  4. QDataStream use
    By Doug Broadwell in forum Qt Programming
    Replies: 2
    Last Post: 21st July 2007, 22:17
  5. Reading QByteArray from QDataStream Qt3.3
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 20: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.