PDA

View Full Version : Help with QDataStream and QByteArray



P@u1
27th June 2011, 18:02
Hi everyone,

I have the follwing function:


template<class T>
void SubmitData(const QString& name, const SCVitalSignInformation& vsi, const T& data)
{
Triple<SCVitalSignInformation, QByteArray, int>*& p = m_map[name];
if(p == NULL)
{
p = new Triple<SCVitalSignInformation, QByteArray, int>;
}
p->first = vsi;
QByteArray & buffer = p->second;
QDataStream stream(&buffer, QIODevice::ReadWrite);
stream << data;
++(p->third);
}


I checked it with the debugger and recognized, that the VitalSignInformation and the int are changed, but the buffer remains unchanged, although i write to it with operator<<...
Triple is just a little class similar to std::pair (but with 3 elements)
And m_map is this:
std::map<QString, Triple<SCVitalSignInformation, QByteArray, int>* > m_map;
(I'm not using QMap/QHash as it does not have a swap memberfunction in the current qt-version.)

I think the problem occurs either because I use QDataStream and/or QByteArray in a wrong way, or I did just some dumb mistake^^

It would be nice if you can help me!
Thanks in advance!

P.S.:
The operator<< is overloaded for the types I use as T of course.

ChrisW67
28th June 2011, 01:25
Are you intending to append to the buffer? If so, you probably want QIODevice::Append. As it is now the seek pointer is probably at byte 0 when you open the stream and this code is overwriting the existing content.

Is there a reason for opening ReadWrite when you only write?