How to get selection changed notification in QTreeView
c++, qt
Solution
the QObject::connect method should be used as follow :
QObject::connect(sender, SIGNAL(signal_method), receiver, SLOT(slot_method));
so in your case it should be something like
connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), this, SLOT(mySelectionChanged(const QItemSelection&,const QItemSelection&)));
Problem
I am trying to figure this out and it seems like I have to use QItemSelectionModel but I can't find an example how to wire things up. I have defined in .h file. ``` QItemSelectionModel* selectionModel; ``` Now in constructor of the view, I set: ``` selectionModel = ui->treeView->selectionModel(); // the following line is not compiling! connect(ui->treeView->selectionModel(), SIGNAL( ui->treeView->selectionModel(const QModelIndex&, const QModelIndex &) ), this, this->selectionChanged ( QItemSelection & sel, QItemSelection & desel) ); ``` I thought there would be predefined slot but I can't find one so I added this one (the syntax of which I found here) ``` void MyDialog::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { qDebug() << "Item selection changed"; } ``` I also tried replacing QItemSelection with QModelIndex but still doesn't work. What do I need to do in order to simply get notified when selection has changed and than obviously grab the newly selected item?