Daniel's answer is correct, but itβs better to show it with an example suitable for beginners:
class MyCustomModel : public QAbstractListModel { Q_OBJECT public: ImageCollectionModel(QObject *parent, MyCustomCollection *data); : QObject(parent) , m_myData(data) { } public slots: void onSelectedItemsChanged(QItemSelection selected, QItemSelection deselected) {
When you pass your custom model to QListView, this is a great opportunity to connect it:
ui->myListView->setModel(m_myModel); connect(ui->myListView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), m_myModel, SLOT(onSelectedItemsChanged(QItemSelection, QItemSelection)));
source share