PDA

View Full Version : QByteArray,QDataStream Question



aash_89
21st July 2010, 21:42
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

Zlatomir
21st July 2010, 21:48
You can use ReadWrite from the beginning, or create another QDataStream for reading

aash_89
21st July 2010, 21:52
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.

Zlatomir
21st July 2010, 22:40
QDataStream it isn't just "for" QByteArray, it's for serialization of your data to an io device (file, etc...) Read the documentation here (http://doc.trolltech.com/4.6/qdatastream.html).