I cannot tell you why you are losing data.
It is easy enough to do a simple experiment to find out if the sort of manipulations you do will cause a deep copy:
#include <QtCore>
#include <QDebug>
int main(int argc, char **argv)
{
char buf[] = "....";
qDebug() << buf << a << b; // all point to buf and show same data
buf[0] = 'X'; // modify original buffer directly
qDebug() << buf << a << b; // all changed because the share the buffer
b[0] = 'Y'; // change using the byte array interface causes deep copy
qDebug() << buf << a << b; // only b changed after deep-copy
}
#include <QtCore>
#include <QDebug>
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
char buf[] = "....";
QByteArray a = QByteArray::fromRawData(buf, 4);
QByteArray b = a; // shallow copy of a
qDebug() << buf << a << b; // all point to buf and show same data
buf[0] = 'X'; // modify original buffer directly
qDebug() << buf << a << b; // all changed because the share the buffer
b[0] = 'Y'; // change using the byte array interface causes deep copy
qDebug() << buf << a << b; // only b changed after deep-copy
}
To copy to clipboard, switch view to plain text mode
Output:
.... "...." "...."
X... "X..." "X..."
X... "X..." "Y..."
.... "...." "...."
X... "X..." "X..."
X... "X..." "Y..."
To copy to clipboard, switch view to plain text mode
Bookmarks