Joe Carr Joe Carr - 5 months ago 51
C++ Question

Qt changing an item within a char array

I am struggling with changing the 4th byte in a char array with hexes inside. I need to change the 4th byte (0x00) in the char str[5].

Is there any built in library or a command which I can use for my code?

QString setVal = QString::number( ui->gainSpinBox->value(), 16 ).toUpper();
ui->statusBar->showMessage(setVal, 3000);

char str [5] = {0xE6, 0x05, 0x01, 0x00, 0xe6};


First of all, a char array has chars inside, not "hexes". The latter is your formatting choice.

str[3] = '\0' sets the fourth element of str to 0, but since it's zero anyway, this is a no-op.

'\0' is a char type, which is why I've written it this way.