Results 1 to 9 of 9

Thread: QDataStream and readBytes

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Arrow Re: QDataStream and readBytes

    Ok. last step:

    this doesn't work...

    Qt Code:
    1. quint16 dataLength=0;
    2.  
    3. QDataStream inData(&tcpSocket);
    4.  
    5. while (zerocount < 4 && dataLength==0)
    6. {
    7. inData >> dataLength;
    8. if (dataLength==0) zerocount++;
    9. }
    10.  
    11. // exceed number of tries... bogus txs. return.
    12. if (zerocount==3) return;
    13.  
    14. char * data = new char[dataLength];
    15. inData >> data;
    To copy to clipboard, switch view to plain text mode 

    the data is always 0x0 ...
    So ... please tell me... after in >> dataLength the pointer in the stream is advanced or not?
    the operator>> ( char *& s ) is able to convert the binary data into char?

    Thanks in advance.
    Last edited by jpn; 18th January 2008 at 20:33. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QDataStream and readBytes

    bump.

    Must one do this?

    Qt Code:
    1. char * data = new char[dataLength];
    2. qint8 c;
    3. int n;
    4. for (n=0; n<dataLength; n++) {
    5. inData >> c;
    6. data[n]=c;
    7. }
    To copy to clipboard, switch view to plain text mode 

    It feels a bit archaic...

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDataStream and readBytes

    Quote Originally Posted by pdoria View Post
    Must one do this?
    No, you can use readRawData() instead.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDataStream and readBytes

    Be aware that QDataStream is not a general purpose binary stream but a serialization method. Don't use it if you don't need it.

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
  •  
Qt is a trademark of The Qt Company.