Results 1 to 7 of 7

Thread: QByteArray overrides

Hybrid View

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

    Default Re: QByteArray overrides

    You don't have to cast nor to use unions.
    The scheme is:
    Qt Code:
    1. ba.resize(1000);
    2. int x, y, z;
    3. char *data = ba.data();
    4. memcpy(data, &x, sizeof(x));
    5. memcpy(data+sizeof(x), &y, sizeof(y));
    6. memcpy(data+sizeof(x)+sizeof(y), &z, sizeof(z));
    To copy to clipboard, switch view to plain text mode 
    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.


  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QByteArray overrides

    Thanks wysota, I didn't know whether or not accessing the internal data of a QByteArray was frowned upon or not, or could cause potential problems. I was also going to use append as it guarantees the space is available, and resizes if not, but I guess I can calculate the amount of space required by the quint32's at least (at the moment, I just over-estimate and 'reserve' the amount rather than a resize).

Similar Threads

  1. Regarding qbytearray
    By mohanakrishnan in forum Qt Programming
    Replies: 7
    Last Post: 19th November 2009, 13:38
  2. Replies: 9
    Last Post: 25th July 2009, 13:27
  3. QGtkStyle - Ignores QPalette color overrides
    By chezifresh in forum Qt Programming
    Replies: 1
    Last Post: 9th July 2009, 01:49
  4. Qwt overrides Widget background
    By garfield in forum Qwt
    Replies: 1
    Last Post: 18th December 2007, 08:16
  5. QByteArray in Qt3
    By joseph in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2007, 06:16

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.