Results 1 to 8 of 8

Thread: PlEASE HELP: Hot To Use Byte Array, data stream

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    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: PlEASE HELP: Hot To Use Byte Array, data stream

    Qt Code:
    1. QDataStream data(&arr,QIODevice::ReadWrite);
    2. data.setVersion(QDataStream::Qt_4_6);
    3. data<<(quint16(0))<<quint8('S');
    4. data<<message;
    5. data<<(quint8('L'));
    6. data.device()->seek(0);
    7. data<<(arr.size()-sizeof(quint16)); // How many bytes are being written here?
    8. tBrowser->append(QString::number(type2));
    To copy to clipboard, switch view to plain text mode 

    When I try a quick test:
    Qt Code:
    1. QString message("ABCDEF");
    2.  
    3. QDataStream data(&arr,QIODevice::ReadWrite);
    4. data.setVersion(QDataStream::Qt_4_6);
    5. data<< quint16(0xBEEF) <<quint8('S');
    6. data<<message;
    7. data<<(quint8('L'));
    8. qDebug() << arr.toHex();
    9. data.device()->seek(0);
    10. data << (arr.size() - sizeof(quint16));
    11. qDebug() << arr.toHex();
    12. data.device()->seek(0);
    To copy to clipboard, switch view to plain text mode 
    I get 18 bytes (0x00000012 bytes) excluding the size field:
    Qt Code:
    1. "beef530000000c0041004200430044004500464c"
    2. "0000001200000c0041004200430044004500464c"
    To copy to clipboard, switch view to plain text mode 
    I think you can see the problem now.

    PS: Were you expecting Unicode characters at the receiving end?
    Last edited by ChrisW67; 16th July 2010 at 06:46. Reason: Added afterthought

Similar Threads

  1. Replies: 3
    Last Post: 19th April 2010, 14:16
  2. 2D array data plot!
    By kahramonj in forum Qwt
    Replies: 3
    Last Post: 21st March 2009, 11:48
  3. reading utf8 as data stream.
    By kami in forum Newbie
    Replies: 1
    Last Post: 28th September 2008, 21:48
  4. Is it possible to stream data from device with phonon ?
    By Elder Orb in forum Qt-based Software
    Replies: 0
    Last Post: 24th July 2008, 19:58
  5. Creating a Pixmap out of an array of data
    By toratora in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2007, 19:00

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.