Hi,
I'm having problems extracting contents from a QByteArray...
Given the code:
unitData=tcpSocket.readAll(); // incoming binary data
.
.
.
const char *c_str = unitData.toHex().data();
cout << "Received: " << c_str << endl;
QByteArray unitData;
unitData=tcpSocket.readAll(); // incoming binary data
.
.
.
const char *c_str = unitData.toHex().data();
cout << "Received: " << c_str << endl;
To copy to clipboard, switch view to plain text mode
outputs correctly:
000F353334...yacka yacka...
but when one tries:
{
bool ok;
// check the # of bytes in the header
unsigned int nbrBytes = data.left(2).toUInt(&ok,16);
if (!ok) cout << "Conversion impossible!" << endl;
cout << "# bytes: " << nbrBytes << endl;
}
void myUnit::checkImei (QByteArray &data)
{
bool ok;
// check the # of bytes in the header
unsigned int nbrBytes = data.left(2).toUInt(&ok,16);
if (!ok) cout << "Conversion impossible!" << endl;
cout << "# bytes: " << nbrBytes << endl;
}
To copy to clipboard, switch view to plain text mode
number of bytes is *always* zero! 
Any pointers would be highly appreciated...
Kind regards,
Pedro Doria Meunier
Bookmarks