How can I assign a byte value to a specific index of a bytearray without causing its size to change??
-
this seems like a no brainer but I can´t for the life of me figure this out...
I tried...
@
TX_Buffer.replace(sizeof(TX_Msg), 1, &((DI.mid(2, 2).toInt(&ok, 16) + 0x33) % 256));
@but get and error :
error: lvalue required as unary ‘&’ operand -
Try this:
@QByteArray ba("Hello world");
char *data = ba.data();
ba.data()[1] = 'B';
qWarning() << ba; //shows "HBllo world"
@size() always returns 11.
-
Your third argument
@&((DI.mid(2, 2).toInt(&ok, 16) + 0x33) % 256)@
to replace is not an C++ object (which you can get an address with &), but an integer.
Danilo:
@ba[1] = 'B';@
should do the trick even shorter -
Outch, my bad... You're right.
-
No problem - it was a long and hard week, so even the cutest brain gets exhausted sometimes :-)
-
thanks guys!