Is it permissible to mix serialization of data and readRawData/writeRawData to a QDataStream?

In other words, imagine I have information stored in a class that I'd like to transfer over the network using QDataStream, and imagine I have a pointer to that object:

Qt Code:
  1. myClass *myObject = new myClass;
To copy to clipboard, switch view to plain text mode 

Would it be OK to do something like this:

Qt Code:
  1. ... // assume 'out' is a QDataStream object.
  2. out << (quint16)0; // Initialize "bytes of data" to 0
  3. out.writeRawData((char *)myObject, myObject->sizeInBytes()); // put binary data into stream
  4. out.device()->seek(0); // seek back to beginning of stream
  5. out << (quint16)(out.size() - sizeof(quint16)); // set the "bytes of data"
To copy to clipboard, switch view to plain text mode 

Or would it confuse Qt?

Same question for input of binary data using readRawData() ...

Thanks,

Gordon E.