PDA

View Full Version : QDataStream use



Doug Broadwell
21st July 2007, 20:34
I'm trying to use a QDataStream to serialize some data into a QByteArray. This needs to be done over multiple function calls: one to initialize it, one to add data to it called 1 to N times, and a call to use the data and finish up. I'm not sure how to do this (which might again be my lack of expertise with C++ and/or Qt). If I make the QDataStream a private class variable, there isn't a QDataStream.setDevice() for a QByteArray so I don't know how to init it, I can't use a QDataStream* as << and >> requires a QDataStream&.

Help.

Thanks.

marcel
21st July 2007, 20:45
What about adding a pointer to a QDataStream member variable?
And then:


void SomeClass::initDataStream()
{
mDataStream = new QDataStream( yourByteArray );
}
As for writing to the data stream, you can use:


*mDataStream << someInput;
This is pretty clear. Don't forget to delete the data stream when you're finished with it.

Regards

Doug Broadwell
21st July 2007, 22:17
Thanks so much.

Doug