Results 1 to 5 of 5

Thread: QByteArray

  1. #1
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QByteArray

    Hi all!

    I created QByteArray dynamically- QByteArray(NULL, BUFFER_SIZE) I want it to do this:
    I want "N" bytes of some "DATA" to be copied to this QByteArray. So something like memcpy function does. Is there any method like this ? I was lookig for it but no success I can do that in for cycle but that's not good
    Is there any other function I could use for doing this ?
    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray

    See QByteArray::append(const char*) or QByteArray::data ( the non-const version).
    With the latter you could use memcpy, but you'll have to allocate it first( I think, it is not tested). The first one is safer, just appends the buffer.

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

    Default Re: QByteArray

    See QByteArray::data() for a pointer to the data buffer and QBuffer for a QIODevice interface to the byte array. You can use either way to fill the byte array.

  4. #4
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QByteArray

    Well, Wysota's ideas are very close to what I want.
    The thing is that I already have data in my own data buffer:

    const char* data.

    and I want only : int buffer_size number of these data to be copied to my
    QByteArray

    data() return a pointer to the data stored in QByteArray that I know.
    BUT how to COPY data into it ?? Append add all data in buffer...I need only "buffer_size" bytes.
    Thanks

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QByteArray

    Oh, then you might want to try:
    QByteArray::QByteArray ( const char * data, int size )
    Constructs a byte array containing the first size bytes of array data.
    If data is 0, a null byte array is constructed.
    QByteArray makes a deep copy of the string data.
    But this way you can only copy the first size bytes.

Similar Threads

  1. QByteArray with network data
    By merlvingian in forum Qt Programming
    Replies: 1
    Last Post: 1st June 2007, 17:53
  2. QDomElement to QByteArray ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 2nd May 2006, 17:01
  3. How to display a QByteArray as an Image ?
    By probine in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 13:45
  4. Reading QByteArray from QDataStream Qt3.3
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 20:23
  5. How to read a Number from the QByteArray
    By antonio.r.tome in forum Qt Programming
    Replies: 2
    Last Post: 24th February 2006, 15:24

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.