Results 1 to 2 of 2

Thread: Help with QDataStream and QByteArray

  1. #1
    Join Date
    Jun 2011
    Posts
    38
    Thanks
    8
    Thanked 1 Time in 1 Post

    Default Help with QDataStream and QByteArray

    Hi everyone,

    I have the follwing function:
    Qt Code:
    1. template<class T>
    2. void SubmitData(const QString& name, const SCVitalSignInformation& vsi, const T& data)
    3. {
    4. Triple<SCVitalSignInformation, QByteArray, int>*& p = m_map[name];
    5. if(p == NULL)
    6. {
    7. p = new Triple<SCVitalSignInformation, QByteArray, int>;
    8. }
    9. p->first = vsi;
    10. QByteArray & buffer = p->second;
    11. QDataStream stream(&buffer, QIODevice::ReadWrite);
    12. stream << data;
    13. ++(p->third);
    14. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Help with QDataStream and QByteArray

    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?

Similar Threads

  1. QDataStream and QByteArray issue
    By sepehr in forum Qt Programming
    Replies: 13
    Last Post: 2nd April 2021, 16:41
  2. QTcpSocket QDataStream QByteArray
    By Grimlock in forum Newbie
    Replies: 1
    Last Post: 14th December 2009, 22:47
  3. Replies: 9
    Last Post: 25th July 2009, 13:27
  4. how QDataStream and QByteArray related
    By dognzhe in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2009, 08:45
  5. Reading QByteArray from QDataStream Qt3.3
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 20:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.