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. Warning in Qt 5: "Using QCharRef with an index pointing outside the valid range of a QString"
Forum Updated to NodeBB v4.3 + New Features

Warning in Qt 5: "Using QCharRef with an index pointing outside the valid range of a QString"

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 2.3k 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.
  • AitorQtA Offline
    AitorQtA Offline
    AitorQt
    wrote on last edited by
    #1

    Hi!

    I have upgraded to Qt 5.15.2, using Qt Creator 4.14.2 and gcc 7.3.1 under Ubuntu Linux. I'm compiling my
    project but I am seeing this annoying Warning everywhere:
    "Using QCharRef with an index pointing outside the valid range of a QString. The corresponding behavior is deprecated, and will be changed in a future version of Qt."

    I want to supress this warning. Anyone can help me to know how to do it?

    Thanks!

    Christian EhrlicherC 1 Reply Last reply
    0
    • AitorQtA AitorQt

      Hi!

      I have upgraded to Qt 5.15.2, using Qt Creator 4.14.2 and gcc 7.3.1 under Ubuntu Linux. I'm compiling my
      project but I am seeing this annoying Warning everywhere:
      "Using QCharRef with an index pointing outside the valid range of a QString. The corresponding behavior is deprecated, and will be changed in a future version of Qt."

      I want to supress this warning. Anyone can help me to know how to do it?

      Thanks!

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @AitorQt said in Warning in Qt 5: "Using QCharRef with an index pointing outside the valid range of a QString":

      I want to supress this warning. Anyone can help me to know how to do it?

      Fix your 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
      0
      • AitorQtA Offline
        AitorQtA Offline
        AitorQt
        wrote on last edited by
        #3

        There is no error, just an unending list of warning which avoid me focusing in the real errors and warnings.

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

          @AitorQt said in Warning in Qt 5: "Using QCharRef with an index pointing outside the valid range of a QString":

          There is no error

          You're using an undocumented behavior which was removed in Qt6 so your app will crash with Qt6 and is using some undefined stuff in Qt5 so fix it. If you don't like it then don't ask how to fix it.

          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
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi
            Just to be sure I understand.
            so this auto-extend feature
            https://doc.qt.io/qt-5/qstring.html#operator-5b-5d
            was removed and hence the warning ?

            1 Reply Last reply
            0
            • AitorQtA Offline
              AitorQtA Offline
              AitorQt
              wrote on last edited by
              #6

              Now I understand @mrjj .
              So, that means that using a so common operation like
              QString str;
              str[1] == ...
              is deprecated? Then how is it supposed to be done? That has to do with the COW string to avoid expensive copies of strings, isn't it?

              Thanks for the answer

              JonBJ 1 Reply Last reply
              0
              • AitorQtA AitorQt

                Now I understand @mrjj .
                So, that means that using a so common operation like
                QString str;
                str[1] == ...
                is deprecated? Then how is it supposed to be done? That has to do with the COW string to avoid expensive copies of strings, isn't it?

                Thanks for the answer

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by JonB
                #7

                @AitorQt
                I had no idea that str[1] == ... or str[1] = ... beyond the string length was ever allowed, and would never have used it!

                For your == question, what is wrong with if (str.length() > 1 && str[1] == ...)?

                For =, what about something like str.resize(2, ' '); str[1] = ...;?

                1 Reply Last reply
                0
                • AitorQtA Offline
                  AitorQtA Offline
                  AitorQt
                  wrote on last edited by
                  #8

                  I have tested it.
                  Just adding the QString headers create the error. Doing just this.

                  #include <QString>
                  #include <QStringList>

                  int dummy = 1;

                  I run that and the warning appears 4 times! I suppose that the warning comes from the QStringList.h inside, probably the
                  library itself is doing it.

                  JonBJ 1 Reply Last reply
                  0
                  • AitorQtA AitorQt

                    I have tested it.
                    Just adding the QString headers create the error. Doing just this.

                    #include <QString>
                    #include <QStringList>

                    int dummy = 1;

                    I run that and the warning appears 4 times! I suppose that the warning comes from the QStringList.h inside, probably the
                    library itself is doing it.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #9

                    @AitorQt
                    ? I have used Qt 5 for years without seeing such a warning, from its own header files? Your warning(s) should give the file/line number? Is that really inside their Qt code?

                    1 Reply Last reply
                    0
                    • AitorQtA Offline
                      AitorQtA Offline
                      AitorQt
                      wrote on last edited by
                      #10

                      Ok, I have found it.

                      The error was trying to access an empty QString.

                      QString str = "";

                      str[0] == ...
                      that was the reason for the error

                      Christian EhrlicherC 1 Reply Last reply
                      1
                      • AitorQtA AitorQt

                        Ok, I have found it.

                        The error was trying to access an empty QString.

                        QString str = "";

                        str[0] == ...
                        that was the reason for the error

                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @AitorQt said in Warning in Qt 5: "Using QCharRef with an index pointing outside the valid range of a QString":

                        That was the reason for the error

                        It was a warning, not an error.

                        Please mark the topic as solved then.

                        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
                        0
                        • AitorQtA Offline
                          AitorQtA Offline
                          AitorQt
                          wrote on last edited by
                          #12

                          Yeah, done!

                          1 Reply Last reply
                          0

                          • Login

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