Qt World Summit: Register Today!

2 overloads have similar conversions...

  • Hi All I am executing a if statement on a bytearray as follows:

     if (data_total[2] == 0x01)
    //do stuff

    When I compiled with MsGW this worked fine. I have recently moved to MSVC2017 compiler (as I need to use QWebEngine), and now I get this error:

    C:\PMPS\PMPSv1\pmps_f.cpp:1516: error: C2666: 'QByteRef::operator ==': 2 overloads have similar conversions

    Any ideas on how to use a for statement when investigating the hex value in a bytearray?


  • Moderators

    I'd recommend using at() instead of op. []. Then you're certain you are using the const version of the method and won't accidentally overwrite a byte.

    Regading your issue: atting explicit int/uint conversion could perhaps help:

     if (data_total[int(2)] == 0x01)

  • Lifetime Qt Champion


    Compare it with a char:

    if (data_total[2] == '\x01') {
         // do stuff

  • @James-Sprinks
    Assuming you mean your array is a QByteArray, that uses unsigned char.

    The best way to initialize/compare with constant values is to use the U suffix to mark the value as unsigned, i.e.:

    if (data_total[2] == 0x01U)

    I'm not sure, but if you use @SGaist 's '\x01' char mechanism I think some places (e.g. certainly in an initializer) you will get a signed/unsigned warning if the value has the top bit set (e.g. '\xFF') .....

Log in to reply