View Full Version : QByteArray::operator QNoImplicitBoolCast() const' is private

11th June 2012, 09:12
void rs485::rs485DataAquisition(QByteArray data) //0-SubSystem---------1-Pid--------2-Value
QByteArray receivedData;
unsigned char address;

qDebug() << "rs485DataAquisition()" << data.toHex();

if(data.toHex() < "0x06")

if( data.toHex() < _ENGINEROOM_SUBS )
{//Engine Compartment Elements

qDebug() << "Engine Compartment Elements";

if(data.size() == 1)
qDebug() << "Reading request..";

if(rs485WriteData(_READ_ENGINEADDRESS, data.toHex())) // I get the error here, the second parameter of this function is unsigned char

qDebug() << "NOW -> rs485CheckAck()";

11th June 2012, 10:06
The second parameter you are passing to that function is not unsigned char, it is a QByteArray. Further, the byte array you are using is a string representation of the bytes in the array in hex: a very different thing to the actual bytes that you almost certainly want to be sending. The first byte in the QByteArray is an unsigned char:

if(rs485WriteData(_READ_ENGINEADDRESS, data.at(0)))

It seems you are generally confused about the difference between the value in a byte and the string representation of it. If you want to compare the value of the first byte in the QByteArray then do so directly, don't convert to a string and then compare. So, line 8 becomes:

if (data.at(0) < 0x06) // notice no quotes and no toHex(), or
if (data.at(0) < 6) // same thing in decimal

and line 10:

if( data.toHex() < _ENGINEROOM_SUBS )

I am assuming that _READ_ENGINEADDRESS and _ENGINEROOM_SUBS are defined integer literals in hex like


which lead to think you needed to convert your byte array to a hex string.

12th June 2012, 00:57
Just noticed a glitch in my last post. Line 10 should be something like:

if( data.at(0) < _ENGINEROOM_SUBS )

where you select the appropriate byte from the array to compare.