Unsolved QByteArray deprecated functionality
-
Hello, I have recently upgraded to Qt 5.14 and I am using the QByteArray class which is now giving me a message about future deprecation of the index operator (https://doc.qt.io/qt-5/qbytearray.html#operator-5b-5d). So I was wondering, what is the new function that you should use instead to keep the same functionality? If I use insert() or replace(), it seems to also be increasing the size of the byte array. All I want is to edit an existing byte at an index.
Thanks.
-
Can you show us some code?
-
@Kayote
I think you may be misinterpreting what the link you quote is stating:Note: Before Qt 5.14 it was possible to use this operator to access a character at an out-of-bounds position in the byte array, and then assign to such a position, causing the byte array to be automatically resized. Furthermore, assigning a value to the returned QByteRef would cause a detach of the byte array, even if the byte array has been copied in the meanwhile (and the QByteRef kept alive while the copy was taken). These behaviors are deprecated, and will be changed in a future version of Qt.
I'm thinking that states the behaviours (accessing out-of-bounds) are what will be deprecated, not the whole usage of
QByteRef QByteArray::operator[](int i)
. (But maybe not if you are saying you get warnings now regardless.)https://doc.qt.io/qt-5/qbytearray.html#at can be used to read from a
QByteArray
. One of thereplace()
overloads should work for replacing, if you say the size is growing it sounds like you are replacing with more characters than the number you are removing.