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 doesn't accept 0x00.
Qt 6.11 is out! See what's new in the release blog

QByteArray doesn't accept 0x00.

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.3k 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.
  • P Offline
    P Offline
    PolywickStudio
    wrote on last edited by
    #1

    I found a bug.

    {
    QByteArray ab;
    ab.append(0x00); // error. Huh?
    }

    JonBJ 1 Reply Last reply
    0
    • P PolywickStudio

      I found a bug.

      {
      QByteArray ab;
      ab.append(0x00); // error. Huh?
      }

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @PolywickStudio
      Why do you think there is any bug (there won't be)? What does // error. Huh? mean, there is no error. I would guess whatever way you are trying to see/determine what ends up in your ab is incorrect, so state exactly what you do to "discover" this has "gone wrong"?

      1 Reply Last reply
      2
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        This is what GCC gives me:

        main.cpp: In function ‘int main(int, char**)’:
        main.cpp:10:18: error: call of overloaded ‘append(int)’ is ambiguous
           10 |         ab.append(0x00);
              |         ~~~~~~~~~^~~~~~
        In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:50,
                         from /usr/include/x86_64-linux-gnu/qt5/QtCore/qcoreapplication.h:44,
                         from /usr/include/x86_64-linux-gnu/qt5/QtCore/QCoreApplication:1,
                         from main.cpp:1:
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h:307:17: note: candidate: ‘QByteArray& QByteArray::append(char)’
          307 |     QByteArray &append(char c);
              |                 ^~~~~~
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h:309:17: note: candidate: ‘QByteArray& QByteArray::append(const char*)’
          309 |     QByteArray &append(const char *s);
              |                 ^~~~~~
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h:311:17: note: candidate: ‘QByteArray& QByteArray::append(const QByteArray&)’
          311 |     QByteArray &append(const QByteArray &a);
              |                 ^~~~~~
        /usr/include/x86_64-linux-gnu/qt5/QtCore/qstring.h:1508:20: note: candidate: ‘QByteArray& QByteArray::append(const QString&)’
         1508 | inline QByteArray &QByteArray::append(const QString &s)
              |                    ^~~~~~~~~~
        

        The compiler cannot tell what variation this call should match and does its best to be helpful.
        Should it convert the int literal to char, a (null) pointer to a C-style string, a QString or QByteArray via their constructors?
        Variations that match only one possibility:

                ab.append('\0');  // most traditional
                ab.append('\x00');
                ab.append(static_cast<char>(0x00));   // Yuck!
        
        1 Reply Last reply
        6
        • P Offline
          P Offline
          PolywickStudio
          wrote on last edited by
          #4

          OK, my bad. thank you for the advice on using '\0' or '\x00';

          1 Reply Last reply
          0
          • P PolywickStudio has marked this topic as solved on

          • Login

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