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 deprecated functionality
Forum Updated to NodeBB v4.3 + New Features

QByteArray deprecated functionality

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 483 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.
  • K Offline
    K Offline
    Kayote
    wrote on last edited by Kayote
    #1

    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.

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Can you show us some code?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • K 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.

        Thanks.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @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 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.

        1 Reply Last reply
        3

        • Login

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