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. Indecipherable backtrace on a segfault
Forum Updated to NodeBB v4.3 + New Features

Indecipherable backtrace on a segfault

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 553 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.
  • S Offline
    S Offline
    swurl
    wrote on last edited by
    #1

    I'm seeing random crashes in my app, usually happening shortly after adding things to a QML TreeView (which uses a QStandardItemModel underneath the hood). The backtrace is completely indecipherable. What's going on?

    236ad4dd-f04c-4e62-bb84-f7f0f60b0664-image.png

    1 Reply Last reply
    0
    • S Offline
      S Offline
      swurl
      wrote on last edited by
      #8

      Oh, turns out it was because I was calling add in a different thread. Oops, I completely forget about that. Fixed by using QMetaObject::invokeMethod.

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Are you returning any custom data structure from your model ?

        How are you populating it ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • S Offline
          S Offline
          swurl
          wrote on last edited by swurl
          #3

          @SGaist
          Forgot to post my code. Version is 6.7.2, platform is Linux AMD64

          Model:

          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.

          1 Reply Last reply
          0
          • Axel SpoerlA Offline
            Axel SpoerlA Offline
            Axel Spoerl
            Moderators
            wrote on last edited by
            #4

            Add debugging to the method and output the argument at the beginning.
            The code will crash if the argument is “/“.

            Software Engineer
            The Qt Company, Oslo

            S 1 Reply Last reply
            2
            • Axel SpoerlA Axel Spoerl

              Add debugging to the method and output the argument at the beginning.
              The code will crash if the argument is “/“.

              S Offline
              S Offline
              swurl
              wrote on last edited by
              #5

              @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
                      }
                  }
              }
              
              1 Reply Last reply
              0
              • S Offline
                S Offline
                swurl
                wrote on last edited by
                #6

                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?

                S 1 Reply Last reply
                0
                • S swurl

                  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?

                  S Offline
                  S Offline
                  swurl
                  wrote on last edited by
                  #7

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

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    swurl
                    wrote on last edited by
                    #8

                    Oh, turns out it was because I was calling add in a different thread. Oops, I completely forget about that. Fixed by using QMetaObject::invokeMethod.

                    1 Reply Last reply
                    1
                    • S swurl has marked this topic as solved on

                    • Login

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