How to connect QTableView selection changed Signal

Viewed 840

I inserted a QTableView in my GUI and set selectionMode = SingleSelection , selectionBehavior = SelectRows.

I want to connect my slot to a signal (selection changed or another signal) by changing the selected row.

Please see my code:

connect(ui->tableView->selectionModel(),
    SIGNAL( selectionChanged(const QItemSelection&,
    const QItemSelection&)), this ,SLOT(myslot()));

I get an error message:

QObject::connect: Cannot connect (null)::selectionChanged(const QItemSelection&, const QItemSelection&) to Info::myslot

1 Answers

Without seeing a minimal, reproducible example it's difficult to identify the real source of the problem but the message...

QObject::connect: Cannot connect (null)::selectionChanged(const QItemSelection&, const QItemSelection&) to Info::myslot

suggests that the expression...

ui->tableView->selectionModel()

evaluates to a null pointer. You need to ensure your UI has been set up before making the connection.

Related