Results 1 to 4 of 4

Thread: QByteArray,QDataStream Question

  1. #1
    Join Date
    Jul 2010
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default QByteArray,QDataStream Question

    Hello,
    I am new to Qt programming.

    This is my question:
    when using a byte array in this way:

    QByteArray Message;
    QDataStream stream(&Message,QIODevice::WriteOnly);

    Using the stream to perform certain actions.

    later i want to use "stream" to readonly, or handle another ByteArray.

    How is this done?

    Ive tried

    stream.device()->close();
    stream.device()->setOpenMode(QIODevice::ReadOnly);


    all give errors.

    Thanks
    Aashish

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QByteArray,QDataStream Question

    You can use ReadWrite from the beginning, or create another QDataStream for reading

  3. #3
    Join Date
    Jul 2010
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QByteArray,QDataStream Question

    Point is, is it always requires to create another QDataStream to perform different actions.
    How do i just close the QDataStream so that i dont have to create a new QDataStream but use stream itself.

    Does creating new streams take up memory? or is it just a way to handle QByteArray.

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QByteArray,QDataStream Question

    QDataStream it isn't just "for" QByteArray, it's for serialization of your data to an io device (file, etc...) Read the documentation here.

Similar Threads

  1. QDataStream and QByteArray issue
    By sepehr in forum Qt Programming
    Replies: 13
    Last Post: 2nd April 2021, 16:41
  2. QTcpSocket QDataStream QByteArray
    By Grimlock in forum Newbie
    Replies: 1
    Last Post: 14th December 2009, 22:47
  3. Replies: 9
    Last Post: 25th July 2009, 13:27
  4. how QDataStream and QByteArray related
    By dognzhe in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2009, 08:45
  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.