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. can not append 0x00 into a QByteArray
Forum Updated to NodeBB v4.3 + New Features

can not append 0x00 into a QByteArray

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.8k 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.
  • A Offline
    A Offline
    agmar
    wrote on last edited by agmar
    #1

    Hi,
    I was just checking the functionality of my serial port and i wanted to try sending a 0x00 , but this is what i get -

    error: call of overloaded ‘append(int)’ is ambiguous
    153 | message.append(0x00) ;
    | ~~~~~~~~~~^~
    dff730cb-deff-47cf-92b6-f4c2419457cb-image.png

    but there is no problem using any other value, am i missing something again?
    75c90a6d-42a0-4372-a5b6-af3c83cf035d-image.png

    and yes, i did read the documentation , i know it says that " if count is negative or zero nothing is appended" but this is something that i need to send...

    J.HilkJ JonBJ 2 Replies Last reply
    0
    • A agmar

      Hi,
      I was just checking the functionality of my serial port and i wanted to try sending a 0x00 , but this is what i get -

      error: call of overloaded ‘append(int)’ is ambiguous
      153 | message.append(0x00) ;
      | ~~~~~~~~~~^~
      dff730cb-deff-47cf-92b6-f4c2419457cb-image.png

      but there is no problem using any other value, am i missing something again?
      75c90a6d-42a0-4372-a5b6-af3c83cf035d-image.png

      and yes, i did read the documentation , i know it says that " if count is negative or zero nothing is appended" but this is something that i need to send...

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @agmar simply make it unambiguous.

      message.append(char(0x00));


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • A agmar has marked this topic as solved on
      • A agmar

        Hi,
        I was just checking the functionality of my serial port and i wanted to try sending a 0x00 , but this is what i get -

        error: call of overloaded ‘append(int)’ is ambiguous
        153 | message.append(0x00) ;
        | ~~~~~~~~~~^~
        dff730cb-deff-47cf-92b6-f4c2419457cb-image.png

        but there is no problem using any other value, am i missing something again?
        75c90a6d-42a0-4372-a5b6-af3c83cf035d-image.png

        and yes, i did read the documentation , i know it says that " if count is negative or zero nothing is appended" but this is something that i need to send...

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

        @agmar said in can not append 0x00 into a QByteArray:

        but there is no problem using any other value, am i missing something again?

        Your question des not state what type message is --- e.g. QByteArray? QString? --- so hard to answer for sure. For reference the issue is that C++ treats an integer value of 0 specially, that matches any pointer type. So for example QByteArray::append() has overloads which take a char ch and const char *str. A value of 0 would match the latter as well as the former (hence the ambiguity), but a value of 1 is not "special" and would not match the const char *str pointer parameter.

        A 1 Reply Last reply
        1
        • JonBJ JonB

          @agmar said in can not append 0x00 into a QByteArray:

          but there is no problem using any other value, am i missing something again?

          Your question des not state what type message is --- e.g. QByteArray? QString? --- so hard to answer for sure. For reference the issue is that C++ treats an integer value of 0 specially, that matches any pointer type. So for example QByteArray::append() has overloads which take a char ch and const char *str. A value of 0 would match the latter as well as the former (hence the ambiguity), but a value of 1 is not "special" and would not match the const char *str pointer parameter.

          A Offline
          A Offline
          agmar
          wrote on last edited by
          #4

          @JonB its in the title :)

          JonBJ 1 Reply Last reply
          0
          • A agmar

            @JonB its in the title :)

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

            @agmar Damn! Well I guessed right anyway... :)

            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