On Oct 20, 2022, at 9:54 AM, Fulko Hew <fulko.hew@xxxxxxxxx> wrote:
> My guess as to what could be wrong according to the error is that
> ba[i] < '\0' is 'always false' because ba (although declared as a QByteArray) is probably
> an unsigned byte array,
Qt 5.12.12 qbytearray.h:
inline char *data();
...
inline char operator[](int i) const;
inline char operator[](uint i) const;
inline QByteRef operator[](int i);
inline QByteRef operator[](uint i);
...
inline char QByteArray::operator[](int i) const
{ Q_ASSERT(uint(i) < uint(size())); return d->data()[i]; }
inline char QByteArray::operator[](uint i) const
{ Q_ASSERT(i < uint(size())); return d->data()[i]; }
...
inline QByteRef QByteArray::operator[](int i)
{ Q_ASSERT(i >= 0); return QByteRef(*this, i); }
inline QByteRef QByteArray::operator[](uint i)
{ return QByteRef(*this, i); }
inline QByteRef QByteArray::front() { return operator[](0); }
inline QByteRef QByteArray::back() { return operator[](size() - 1); }
Definitely signed, unless I'm missing something.
Qt 6.2.4 qbytearray.h:
inline char *data();
...
inline char operator[](qsizetype i) const;
[[nodiscard]] inline char &operator[](qsizetype i);
inline QByteRef operator[](int i);
inline QByteRef operator[](uint i);
...
inline char QByteArray::operator[](qsizetype i) const
{ Q_ASSERT(size_t(i) < size_t(size())); return d.data()[i]; }
...
inline char &QByteArray::operator[](qsizetype i)
{ Q_ASSERT(i >= 0 && i < size()); return data()[i]; }
inline char &QByteArray::front() { return operator[](0); }
inline char &QByteArray::back() { return operator[](size() - 1); }
Also definitely signed, unless I'm missing something.