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

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.

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 5.4k Views 2 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    I'm getting the error in the Application Output displayed when I'm running my application in Qt Creator debugger, I've searched for an instance of QCharRef and it isn't in my source code so is this the result of some library function I'm calling?

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Can also be accessing QString with []
      https://doc.qt.io/qt-5/qstring.html#operator-5b-5d-3

      However, if you cannot find the code then you can use this trick.

      Add a
      https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler

      Then in your new function, simply do string compare on the const QString &msg
      to see if it contains some of the text for that error.
      then put breakpoint in if statement.

      When it hit that breakpoint, then you can see in call stack where in came from.

      1 Reply Last reply
      5
      • SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by SPlatten
        #3

        @mrjj , I've tracked down the source that causes the message to be displayed, but I can't quite see whats wrong with it:

                    foreach(clsXMLnode* pobjChildNode, lstChildNodes) {
                        QString strID = pobjChildNode->strGetAttribute(clsXMLnode::mscszAttrID);
        
                        if ( strID.isEmpty() == true ) {
            //All resizeable nodes must have an ID
                            continue;
                        }
        qDebug() << pobjChildNode->strGetAttribute(clsXMLnode::mscszAttrID) << "[";
                        for( int a=0; a<pobjChildNode->mlstAttrPrs.length(); a++ ) {
                            prAttr* pAttrPr = &pobjChildNode->mlstAttrPrs[a];
                            QString strChildValue(pAttrPr->second);
        
                            if ( strChildValue.indexOf(clsXMLnode::msccPercent) == -1 ) {
            //No content dependant on parent
                                continue;
                            }
                            QString strChildAttr(pAttrPr->first);
        
        qDebug() << strChildAttr << ": " << strChildValue;
                        }
        qDebug() << "]";
                    }
        

        lstChildNodes is an QList of nodes, in the case in question it contains 1 node.
        pobjChildNode->mlstAttrPrs is a QList of attributes pairs (std::pair<QString, QString>), in the case in question it contains 6 pairs:

            [0] first: "id"              second: "frm1"
            [1] first: "x"               second: "2%"
            [2] first: "y"               second: "2%"
            [3] first: "width"           second: "96%"
            [4] first: "height"          second: "96%"
            [5] first: "properties"      second: "QFrame {background-color: #e9efef; background-image: url('meshtile_4x4.png');border: 2px solid #cccccc;border-top-left-radius: 8px;border-top-right-radius: 8px;border-bottom-left-radius: 8px;border-bottom-right-radius: 8px;}"
        

        I've single stepped the code and the error is quire repeatable, when a is 2 and I step over:

        QString strChildAttr(pAttrPr->first);
        

        Thats when the message appears in the Application Output, I cannot see why as its simply creating a copy of the string where pAttrPr->first contains "y" at this point.

        Kind Regards,
        Sy

        mrjjM 1 Reply Last reply
        0
        • SPlattenS SPlatten

          @mrjj , I've tracked down the source that causes the message to be displayed, but I can't quite see whats wrong with it:

                      foreach(clsXMLnode* pobjChildNode, lstChildNodes) {
                          QString strID = pobjChildNode->strGetAttribute(clsXMLnode::mscszAttrID);
          
                          if ( strID.isEmpty() == true ) {
              //All resizeable nodes must have an ID
                              continue;
                          }
          qDebug() << pobjChildNode->strGetAttribute(clsXMLnode::mscszAttrID) << "[";
                          for( int a=0; a<pobjChildNode->mlstAttrPrs.length(); a++ ) {
                              prAttr* pAttrPr = &pobjChildNode->mlstAttrPrs[a];
                              QString strChildValue(pAttrPr->second);
          
                              if ( strChildValue.indexOf(clsXMLnode::msccPercent) == -1 ) {
              //No content dependant on parent
                                  continue;
                              }
                              QString strChildAttr(pAttrPr->first);
          
          qDebug() << strChildAttr << ": " << strChildValue;
                          }
          qDebug() << "]";
                      }
          

          lstChildNodes is an QList of nodes, in the case in question it contains 1 node.
          pobjChildNode->mlstAttrPrs is a QList of attributes pairs (std::pair<QString, QString>), in the case in question it contains 6 pairs:

              [0] first: "id"              second: "frm1"
              [1] first: "x"               second: "2%"
              [2] first: "y"               second: "2%"
              [3] first: "width"           second: "96%"
              [4] first: "height"          second: "96%"
              [5] first: "properties"      second: "QFrame {background-color: #e9efef; background-image: url('meshtile_4x4.png');border: 2px solid #cccccc;border-top-left-radius: 8px;border-top-right-radius: 8px;border-bottom-left-radius: 8px;border-bottom-right-radius: 8px;}"
          

          I've single stepped the code and the error is quire repeatable, when a is 2 and I step over:

          QString strChildAttr(pAttrPr->first);
          

          Thats when the message appears in the Application Output, I cannot see why as its simply creating a copy of the string where pAttrPr->first contains "y" at this point.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          Glad trick worked :)

          I don't see it either.
          QString strChildAttr(pAttrPr->first);
          just copy First QString in the std::pair to the strChildAttr, right ?

          Give it some time. More eyes will come and maybe they can spot it.

          1 Reply Last reply
          0
          • SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #5

            @mrjj , any more thoughts on this?

            Kind Regards,
            Sy

            mrjjM 1 Reply Last reply
            0
            • SPlattenS SPlatten

              @mrjj , any more thoughts on this?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @SPlatten
              Hi
              I tried various constructs to see if i could understand what it could be but
              not sure where that code uses "index pointing outside the valid range of a QString."
              but no hints.
              I assume its like
              https://bugreports.qt.io/browse/QTBUG-81950
              where it is something internal to Qt. Hence staring at your code did bring any light since for me it looks like it just copy the whole string
              and not using [] to do so.

              1 Reply Last reply
              1
              • SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #7

                @mrjj, thanks for taking the time to investigate, very much appreciated.

                Kind Regards,
                Sy

                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