About QByteArray
-
Hello, everyone.
I'm using Qt 5.15.1 + MSVC2019 32bit.
I have a few questions.
When I compile the following codeThere's a warning on line 22.
C4309: 'conversion': truncation of constant valueI think the BYTE range is 256, why?
There is an error on line 23.
call to member function 'append' is ambiguous
candidate functionOn line 15, it's not a problem, so why is it?
Best regards, thank you.
1 #include <Windows.h> 2 3 void MainWindow::on_pushButton_clicked() 4 { 5 BYTE data[5]; 6 data[0] = 0x08; 7 data[1] = 0x86; 8 data[2] = 0x00; 9 data[3] = 0x41; 10 data[4] = 0x53; 11 12 QByteArray Byt; 13 14 for(int i=0; i<5; i++){ 15 Byt.append(data[i]); 16 } 17 18 ui->lineEdit->setText(Byt.toHex(' ')); 19 20 Byt.clear(); 21 Byt.append(0x08); 22 Byt.append(0x86); 23 Byt.append(0x00); call to member function 'append' in ambiguous 24 Byt.append(0x41); 25 Byt.append(0x53); 26 27 ui->lineEdit_2->setText(Byt.toHex(' ')); 28 }
-
@taku-s said in About QByteArray:
BYTE
is probablyunsigned char
, or similar. In lines 21--25 you are passing literal numbers, which areint
s.The warning on #22 is doubtless because
Byt.append(0x86);
has its top bit set/negative value? At a guess, the "ambiguous"Byt.append(0x00);
is because with value0
it could be a pointer and it doesn't know betweenQByteArray &QByteArray::append(char ch)
andQByteArray &QByteArray::append(const char *str)
?Make your constant values
char
s, likechar(0x08)
orunsigned char(0x08)
, or as character constants like'\x08'
.