The next line of code is setting the event handler:

QObject::connect(ui->treeWidget, SIGNAL(clicked(QModelIndex)) (QModelIndex)), this, SLOT(tree_widget_item_selected(QModelIndex))); 

In the tree_widget_item_selected slot, tree_widget_item_selected 'm trying to do the following thing:

 selected = selected.parent(); 

At debug of the given line I receive Segmentation fault . With that, if you do not debug, but simply use the program as intended, everything works as expected.
Win7, Qt 5.1.
What could be the problem?

  • and add a check that selected is not NULL. if (selected) {selected = selected.parent (); else {qDebug () << "selected = NULL"; return; } - KoVadim 5:46
  • @KoVadim writes about the impossibility of casting a QModelIndex to a Boolean type, there is, in principle, a method, isValid is called, it passes normally. The method returns false if the QModelIndex object is empty. - Jeremen1
  • hurried a little. I decided that selected is a pointer. Can you give a minimal example to repeat the bug? - KoVadim 8:40
  • and what example can there be ... selected = selected.parent (); This line is in the loop while selected.isValid (), but the bottom line is that even with the first pass, an error flies ... - Jeremen1

1 answer 1

Stack memory is crashing down at you, this is a system error and you can try to fix it by changing the allocation of memory in it. After all, during debugging, debug-information is added to the code!

  • And how to do it? - Jeremen1
  • four
    @voipp Have you ever looked at Wikipedia what a segmentation fault is before using such wonderful phrases as "breaking stack memory". - Costantino Rupert