QByteArray & QByteArray::setRawData ( const char * datauint size )

Resets the QByteArray to use the first size bytes of the data array. The bytes are not copied. The QByteArray will contain the data pointer. The caller guarantees that data will not be deleted or modified as long as this QByteArray and any copies of it exist that have not been modified.

This function can be used instead of fromRawData() to re-use existings QByteArray objects to save memory re-allocations.

This function was introduced in Qt 4.7.


from : http://qt-project.org/doc/qt-4.8/qbytearray.html#setRawData



[main.cpp]


#include <QByteArray>
#include <QDebug>

int main()
{
  char buf[] = "ABCDEFG";

  QByteArray ba;
  ba.setRawData(buf, 7);
  qDebug() << ba;

  buf[0] = 'a';
  qDebug() << ba;

  return 0;
}




[result]


"ABCDEFG"

"aBCDEFG"




[download]


setrawdata_test.zip