I need to create non-member operator<< and operator>> functions for my custom class so that I can stream them to a QByteArray to push as a BLOB in a mySQL database but I am having some problems in creating my << and >> functions.

I have the following classes
Qt Code:
  1. class siStorage : public QObject
  2. {
  3. ...
  4. QVector<float> *sImage;
  5. float sImageSum;
  6. float sImage2Sum;
  7. }
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. class siStack : public QObject
  2. {
  3. ...
  4. QList<siStorage*> *stack;
  5. }
To copy to clipboard, switch view to plain text mode 
All siStorage in the QList in stack are always the same length, for example 256. And the length of stack can be large, for example > 50,000.

I would like to write << and >> operators that read and write an siStack object.

This is what I currently have:
Qt Code:
  1. QDataStream &operator<< (QDataStream &stream, const siStorage &storage)
  2. {
  3. stream << *(storage.sImage) << storage.siSum << storage.si2Sum;
  4. return stream;
  5. }
  6.  
  7. QDataStream &operator<< (QDataStram &stream, const siStack &stack)
  8. {
  9. for( int = ii = 0; ii < stack.stack.size(); ii++) {
  10. stream << *(stack.stack->at(ii));
  11. }
  12.  
  13. return stream;
  14. }
To copy to clipboard, switch view to plain text mode 
Is this the way I should do this? When I check the size of my resulting QByteArray it is about twice the size of what I would expect. I assume there is some overhead by streaming over 50,000 QVectors but I won't expect that much.

As for the >> operator I have no clue on how to implement it. This will be my first time doing anything like this. Any suggestions or examples will be greatly appreciated.