Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. 2 overloads have similar conversions...
Forum Updated to NodeBB v4.3 + New Features

2 overloads have similar conversions...

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 1.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • James SprinksJ Offline
    James SprinksJ Offline
    James Sprinks
    wrote on last edited by James Sprinks
    #1

    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?

    J

    JonBJ 1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by sierdzio
      #2

      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)
      

      (Z(:^

      1 Reply Last reply
      3
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Compare it with a char:

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        4
        • James SprinksJ James Sprinks

          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?

          J

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @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') .....

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved