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. QByteArray - Ambiguous call to push_back???

QByteArray - Ambiguous call to push_back???

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.4k Views 1 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.
  • E Offline
    E Offline
    ebonnett
    wrote on last edited by
    #1

    Can anyone tell me why this line of code:

    data.push_back(0x00);
    

    causes this error:

    The call to member function 'push_back' is ambiguous?

    aha_1980A 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • E ebonnett

        Can anyone tell me why this line of code:

        data.push_back(0x00);
        

        causes this error:

        The call to member function 'push_back' is ambiguous?

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi @ebonnett,

        there are two overloads: http://doc.qt.io/qt-5/qbytearray.html#push_back-1 and http://doc.qt.io/qt-5/qbytearray.html#push_back-2

        Your zero (0x00) can be converted to a char or a pointer, so the compiler don't know what to to.

        If you want to append a char, use data.push_back(char(0x00)); Appending a nullpointer does not really makes sense, does it?!

        Regards

        Qt has to stay free or it will die.

        E 1 Reply Last reply
        4
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          Because int can bind to multiple overloads of QByteArray::push_back you have to tell the compiler your byte constant is of type char and not the default int: data.push_back(char(0x00)); or data.push_back('\x00');

          E 1 Reply Last reply
          4
          • aha_1980A aha_1980

            Hi @ebonnett,

            there are two overloads: http://doc.qt.io/qt-5/qbytearray.html#push_back-1 and http://doc.qt.io/qt-5/qbytearray.html#push_back-2

            Your zero (0x00) can be converted to a char or a pointer, so the compiler don't know what to to.

            If you want to append a char, use data.push_back(char(0x00)); Appending a nullpointer does not really makes sense, does it?!

            Regards

            E Offline
            E Offline
            ebonnett
            wrote on last edited by
            #5

            @aha_1980 That makes total sense. I did notice that when I cast 0x00 to char, it worked. I just didn't understand the reason. Thank you for the explanation!!!

            1 Reply Last reply
            1
            • VRoninV VRonin

              Because int can bind to multiple overloads of QByteArray::push_back you have to tell the compiler your byte constant is of type char and not the default int: data.push_back(char(0x00)); or data.push_back('\x00');

              E Offline
              E Offline
              ebonnett
              wrote on last edited by
              #6

              @VRonin Thank you for the explanation!

              1 Reply Last reply
              0

              • Login

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