Results 1 to 7 of 7

Thread: QDataStream reading to C++ vectors

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5
    Thanked 86 Times in 81 Posts

    Default Re: QDataStream reading to C++ vectors

    You can write code like
    Qt Code:
    1. ...
    2. char ch;
    3. for (int i = 0; i < size_packet_data; ++i)
    4. {
    5. mybytes >> ch;
    6. payload.push_back(ch);
    7. }
    8. ...
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  2. The following user says thank you to mcosta for this useful post:

    pdoria (23rd July 2009)

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

    Default Re: QDataStream reading to C++ vectors

    Thank you mcosta!

    First thing:

    It'd only compile if :
    Qt Code:
    1. mybytes >> (char *&) ch;
    To copy to clipboard, switch view to plain text mode 

    Secondly I'm wondering if there's a more optimized way to do it beyond a for...next loop

    TY,
    Pedro

  4. #3
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    5
    Thanked 86 Times in 81 Posts

    Default Re: QDataStream reading to C++ vectors

    You can use

    Qt Code:
    1. mybytes >> (qint8) ch;
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

Similar Threads

  1. QFile, QDataStream reading binary data
    By yren in forum Qt Programming
    Replies: 1
    Last Post: 15th April 2009, 06:34
  2. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 20:53
  3. Replies: 8
    Last Post: 27th August 2007, 15:45
  4. QDataStream reading into QString
    By jakamph in forum Qt Programming
    Replies: 4
    Last Post: 15th October 2006, 09:22
  5. Reading QByteArray from QDataStream Qt3.3
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 20:23

Tags for this Thread

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.