[Interest] selectionChanged on remove

Bernhard Lindner private at bernhard-lindner.de
Mon Jun 12 21:36:41 CEST 2017


Hi there!

Could someone please explain me some odd behavior of Qt 5.7 models and
the corresponding selection models?

Please start the "Editable Tree Model" example. Remove all rows except
two. Select the first row. Then set a breakpoint to the following line
of function MainWindow::updateActions() in file mainwindow.cpp:

	int row = view->selectionModel()->currentIndex().row();

Then remove the first row.

When I do this, I can see that the MainWindow::updateActions() function
is called two times. The first time it is called by the signal/slot
connection from the selectionChanged signal; the second time it is
called from MainWindow::removeColumn() by the application.

The problem: In the first call, the new selected row is 1. This is fatal
because after removing the first of two rows there is no row with index
1 anymore.
The second call to MainWindow::updateActions(), done by the application,
fixes that problem but I wonder why it is necessary.

In my application I have the same behavior except that I totally rely on
the seletionChanged() signal... which is why my application crashes.

Is that actually desired behavior?

-- 
Best Regards
Bernhard Lindner

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170612/442a9b56/attachment.sig>


More information about the Interest mailing list