Results 1 to 10 of 10

Thread: QDataStream >>QByteArray [was QByteArray resize not working?!]

Hybrid View

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

    Default Re: QDataStream >>QByteArray [was QByteArray resize not working?!]

    Well ... it's an array of bytes of arbitrary binary content...

    funny thing the compiler is perfectly happy with QDataStream >> QByteArray...
    Why does it fail the call is still beyond me... (and this is exactly the kind of thing that gets you stuck for hours on end )

    To be honest, and never forgetting my place (newbie), I'd call this one a bug on QT4.
    This call should fetch myQByteArray.size bytes from the stream, regardless of content.
    Reading the docs for QByteArray it's stated "QByteArray can be used to store both raw bytes..." so it shouldn't matter what kind of content, or where it came from, one puts in it...


    Bottom line: is there no other (optimized) way than being stuck with this?

    Qt Code:
    1. qint8 c;
    2. for (int i = 0; i < sPacket.size_app_payload; i++) {
    3. records >> c;
    4. sPacket.app_payload[i] = c;
    5. }
    To copy to clipboard, switch view to plain text mode 

    Regarding my other difficulty ...
    I want to extract the first two bytes from it to a quint16

    Could you please show me a way?

    TIA,
    Pedro.

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

    Default Re: QDataStream >>QByteArray [was QByteArray resize not working?!]

    Quote Originally Posted by pdoria View Post
    Well ... it's an array of bytes of arbitrary binary content...
    So it won't work.

    funny thing the compiler is perfectly happy with QDataStream >> QByteArray...
    Because this is syntactically correct.

    Why does it fail the call is still beyond me... (and this is exactly the kind of thing that gets you stuck for hours on end )
    Then read the first sentence of QDataStream documentation and then use QIODevice::read() on the socket directly.

    To be honest, and never forgetting my place (newbie), I'd call this one a bug on QT4.
    It's not a bug, it's a misunderstanding of what QDataStream is.

    This call should fetch myQByteArray.size bytes from the stream, regardless of content.
    No. Make the following experiment:
    Qt Code:
    1. QFile f("test.bin");
    2. f.open(QFile::WriteOnly);
    3. QDataStream dstream(&f);
    4. dstream << 7;
    5. f.close();
    To copy to clipboard, switch view to plain text mode 
    Now go and take a look at size of the created file and its content and everything will become clear.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    pdoria (25th July 2009)

Similar Threads

  1. resize of QMessageBox not working?
    By Sheng in forum Qt Programming
    Replies: 2
    Last Post: 13th November 2008, 14:25
  2. Replies: 2
    Last Post: 22nd January 2008, 16:10
  3. Custom Shape Widget (resize)
    By PiXeL16 in forum Qt Programming
    Replies: 7
    Last Post: 12th February 2007, 07:00
  4. QDomElement to QByteArray ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 2nd May 2006, 17:01
  5. postponing resize event
    By Honestmath in forum Qt Programming
    Replies: 11
    Last Post: 26th February 2006, 00:32

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.