Solved 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'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?
-
Hi
Can also be accessing QString with []
https://doc.qt.io/qt-5/qstring.html#operator-5b-5d-3However, if you cannot find the code then you can use this trick.
Add a
https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandlerThen 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.
-
Hi
Can also be accessing QString with []
https://doc.qt.io/qt-5/qstring.html#operator-5b-5d-3However, if you cannot find the code then you can use this trick.
Add a
https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandlerThen 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.
-
@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.
-
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.
-
@mrjj , any more thoughts on this?
-
@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. -
@mrjj, thanks for taking the time to investigate, very much appreciated.