Re: QByteArray char to int
Quote:
Originally Posted by
pdoria
in251 holds the value: "J[²
This piece of code:
Code:
bool ok;
msgTime = in251.left(4).toUInt(&ok);
if (!ok) printf ("Conversion ERROR!\r\n" );
always returns "Conversion error" and msgTime, of course, is set to zero.
Why can't
.toUint() convert those bytes to an int?
? Have you looked what in251.left(4) gives you back if the value of in251 is "J[²"? That can't work. Use QString::number() to convert a number in a string/byte array!
Code:
qWarning
() <<
QString::number(input251
).
left(4).
toInt();