0
votes

I am trying to create an array of around 4 QDataStreams, one for each QByteArray I have.
The situation is as follows:

struct dataform{  
    //other members  
    QDataStream block;  
}  
dataform gd[4];  
//initialize data for each item in gd[]  
QDataStream out[4];  
for (int i = 0; i < 4; ++i){  
    out[i] = QDataStream(&gd[i].block, QIODevice::WriteOnly);  
}  

The compiler returns

‘QDataStream& QDataStream::operator=(const QDataStream&)’ is private

I have also tried to initialize out with

out[i](&gd[i].block, QIODevice::WriteOnly);  

to no avail; the compiler returns

error: no match for call to ‘(QDataStream) (QByteArray*, QIODevice::OpenModeFlag)’

Is there any way to do this or do I need to make the array an array of QDataStream pointers, allocate the QDataStreams dynamically, and deference the stream every(several hundred times throughout the program) time I write to it?

1

1 Answers

2
votes

You can do this without having to use pointers, but you'll need to add QBuffers in your dataform struct.

Something like (not tested):

struct dataform{  
    //other members  
    QBuffer buffer;
    QDataStream block;  
}  

dataform gd[4];  
QDataStream out[4];  
for (int i = 0; i < 4; ++i){  
    dg[i].buffer.setBuffer(&gd[i].block);
    dg[i].buffer.open(QIODevice::WriteOnly);  
    out[i].setDevice(&dg[i].buffer);
}  

(The QDataStream constructor that takes a QByteArray uses a QBuffer internally according to the docs.)