Indecipherable backtrace on a segfault
-
Hi,
Are you returning any custom data structure from your model ?
How are you populating it ?
-
@SGaist
Forgot to post my code. Version is 6.7.2, platform is Linux AMD64Model:
void TopicListModel::add(const QString &toAdd) { if (toAdd.isEmpty()) return; QStringList split = toAdd.split('/'); if (split.at(0).isEmpty()) split.remove(0); QStandardItem *parentItem = invisibleRootItem(); for (const QString &sub : split) { bool isLast = sub == split.last(); auto results = findItems(sub, Qt::MatchRecursive | Qt::MatchExactly | Qt::MatchWrap); if (results.isEmpty()) { QStandardItem *item = new QStandardItem(sub); if (isLast) { item->setData(toAdd, TLMRoleTypes::TOPIC); } else { item->setData("", TLMRoleTypes::TOPIC); } parentItem->appendRow(item); parentItem = item; } else { for (QStandardItem *item : results) { if (item->parent() == nullptr || item->parent()->text() == parentItem->text()) { parentItem = item; } } } } return; }Omitted some other unrelated and verified-working magic that works with other data.
In essence this works with paths ("Topics") that are split by slashes, and this separates the items accordingly.
The crash is rare and random--at least 95% of the time it works.
The TreeView model it uses is a very slightly modified of the TreeView example.
-
Add debugging to the method and output the argument at the beginning.
The code will crash if the argument is “/“. -
Add debugging to the method and output the argument at the beginning.
The code will crash if the argument is “/“.@Axel-Spoerl Outputting the argument at the beginning and end of the function results in every value I expect to be added to go through fine and output both the beginning and end statements. No "/" is ever passed in, and it seems that the crash is occurring somewhere else.
For good measure, I added an immediate return when the argument is "/". Didn't fix it.
I'm wondering if there's something wrong with my TreeView (even though it's almost the same as the Qt example). Here's the relevant code for that.
TreeView { id: treeView anchors.fill: parent anchors.margins: 10 clip: true boundsBehavior: Flickable.StopAtBounds selectionModel: ItemSelectionModel { } model: <TopicListModel> delegate: Item { implicitHeight: label.implicitHeight * 1.5 implicitWidth: topicView.width - 20 readonly property real indentation: 20 readonly property real padding: 5 // Assigned to by TreeView: required property TreeView treeView required property bool isTreeNode required property bool expanded required property int hasChildren required property int depth required property int row required property int column required property bool current // Rotate indicator when expanded by the user // (requires TreeView to have a selectionModel) property Animation indicatorAnimation: NumberAnimation { target: indicator property: "rotation" from: expanded ? 0 : 90 to: expanded ? 90 : 0 duration: 100 easing.type: Easing.OutQuart } TableView.onPooled: indicatorAnimation.complete() TableView.onReused: if (current) indicatorAnimation.start() onExpandedChanged: indicator.rotation = expanded ? 90 : 0 Rectangle { id: background anchors.fill: parent color: row === treeView.currentRow ? palette.highlight : "black" opacity: (treeView.alternatingRows && row % 2 !== 0) ? 0.3 : 0.1 } Label { id: indicator x: padding + (depth * indentation) anchors.verticalCenter: parent.verticalCenter visible: isTreeNode && hasChildren text: "▶" TapHandler { onSingleTapped: { let index = treeView.index(row, column) treeView.selectionModel.setCurrentIndex(index, ItemSelectionModel.NoUpdate) treeView.toggleExpanded(row) } } font.pixelSize: 17 } Label { id: label x: padding + (isTreeNode ? (depth + 1) * indentation : 0) anchors.verticalCenter: parent.verticalCenter width: parent.width - padding - x - 0 clip: true text: model.name // this is the "sub" variable in the above add method font.pixelSize: 17 } } } -
OK, now I'm really confused.
I commented out the entire delegate to the point that it is now a blank item--no model index references, no nothing.
What else could the QPersistentIndex and QQmlTreeModelToTableModel be referring to?
@swurl
Now I tried two new things:- Removing the
selectionModel - Changed to a
ListView
The former did not fix it, while the latter did.
So... a TreeView with nothing but a model and an anchor or two--no delegate of significance--is causing this crash.
There seems to be something wrong internally with TreeView--or I'm missing some random setting. Either that or the way I'm handling parent-child in my model is somehow wrong.
- Removing the
-
S swurl has marked this topic as solved on
