QByteArray doesn't accept 0x00.
Solved
General and Desktop
-
I found a bug.
{
QByteArray ab;
ab.append(0x00); // error. Huh?
} -
@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 yourab
is incorrect, so state exactly what you do to "discover" this has "gone wrong"? -
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!
-
OK, my bad. thank you for the advice on using '\0' or '\x00';
-