[Qt-interest] QDataStream

phil prentice philp.cheer at talktalk.net
Thu Aug 19 17:55:19 CEST 2010


HI
  I'm using QDataStream to read and write data.  Part of this data consists of 
a fixed length of bytes and so I thought that I could use the member 
functions writeBytes, readBytes or writeRawData, readRawData for that part.

After performing the write I need the reference to the QDataStream, so I 
presume that rules out me using the function writeRawData() because it does 
not return a reference to QDataStream.  If I could get hold of the updated 
reference after the write then read/writeRawData would be perfect for my 
needs.  After a writeRawData() is there anyway I can get the updated 
reference???  Is it effectively updated anyway, because its effectively a 
pointer?

On the other hand writeBytes would work, but readBytes allocates a buffer to 
read into using new....I have my own buffer and simply want to use it direct. 
So I dont want to use this.

If I do something like this will it work?

QDataStream& operator<<(QDataStream& os,
                                const TestResponseDataItem &data) // FRIEND
{
  os << qint8(data.m_voltageRange) << qint8(data.m_testSelected)
        << qint16(data.m_testVoltage) << qint8(data.m_testResistance)
        << qint16(data.m_testFrequency) << qint8(data.m_testPreChargeMode)
        << qint16(data.m_testPreChargeTime);
  // Followed by the test response trace data.
  writeRawData(data.m_testResponseData,
                        TestResponseDataItem::testResponseDataByteCount);
  return os;
}

Because os is a reference is this valid?

or should I simply loop on the buffer writing the data at a byte at a 
time...probably slow??

Thanks for your help

Phil






More information about the Qt-interest-old mailing list