QByteArray comparison



  • Why the statement:

    @
    @ QByteArray data (initialized somehow);
    @
    @ if(data.at(0) == 0xFF)
    @ do_something();
    @

    gives such warning:
    comparison is always false due to limited range of data type [-Wtype-limits].

    You can initialize QByteArray with 0xff value (or not...?), so why cant you compare it?



  • Hi Michelson, welcome to devnet.

    It's because char is signed in your environment (compiler dependent?) and you are comparing something which has range <–128, 127> with 0xFF which is 255.

    This explicit comparisons are fine:
    if((unsigned char)a.at(0) == 0xFF){}
    if(a.at(0) == 'A'){}


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.