As you may have figured out from the title, I'm having problems converting a QByteArray
to an integer.
QByteArray buffer = server->read(8192);
QByteArray q_size = buffer.mid(0, 2);
int size = q_size.toInt();
However, size
is 0. The buffer
doesn't receive any ASCII character and I believe the toInt()
function won't work if it's not an ASCII character. The int size
should be 37 (0x25), but - as I have said - it's 0.
The q_size
is 0x2500
(or the other endianness order - 0x0025
).
What's the problem here ? I'm pretty sure q_size
holds the data I need.
There is no "multi-char split" for a QByteArray . One of: Convert to QString and split if you can safely treat it as a string. Use one of the overloads of QByteArray::indexOf() in a loop to implement your own "split" (which ultimately is doubtless the code split() uses anyway).
bool ok;
q_size.toHex().toInt(&ok, 16);
works for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With