Results 1 to 3 of 3

Thread: split QByteArray

  1. #1
    Join Date
    Oct 2010
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default split QByteArray

    Hi, I have quite large QByteArray and need to split it in smaller (same sized) QByteArrays and possible create QList of these smaller QByteArrays. Let say I have QByteArray with 10 000 bytes and need to split this array to 19 QByteArrays each containing 512 bytes/chars and 1 last QByteArray with remaining bytes...

    I have tried memcpy but it did not work for some reason. Can you give me some hint with example how to do it easily? Initial large QByteArray has not fixed size (ie it's size may vary) so number of QByteArrays has to be set dynamicaly. Size of smaller QbyteArrays may be fixed.
    Thx

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

    Default Re: split QByteArray

    Qt Code:
    1. int pos = 0, arrsize = ba.size(), sizeInArray = 512;
    2. QList<QByteArray> arrays;
    3. while(pos<arrsize){
    4. QByteArray arr = ba.mid(pos, sizeInArray);
    5. arrays << arr;
    6. pos+=arr.size();
    7. }
    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.


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

    xproch13 (29th October 2010)

  4. #3
    Join Date
    Oct 2010
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: split QByteArray

    Huh, simple and great. Thanks

Similar Threads

  1. Replies: 9
    Last Post: 25th July 2009, 13:27
  2. split a QTabWidget?
    By shud in forum Qt Programming
    Replies: 1
    Last Post: 15th July 2009, 19:56
  3. how to split a class ?
    By mimmo_kallon in forum Newbie
    Replies: 0
    Last Post: 8th April 2008, 11:37
  4. More appropriate, section or split?
    By ucntcme in forum Qt Programming
    Replies: 2
    Last Post: 12th October 2007, 12:10
  5. QString split()
    By ShaChris23 in forum Newbie
    Replies: 4
    Last Post: 3rd May 2007, 04:10

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.