Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QByteArray deprecated functionality
Kayote last edited by Kayote
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.
Can you show us some code?
JonB last edited by
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 the
replace()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.