我有以下提升的QTableView:
class QRightClickableTableView : public QTableView {
Q_OBJECT
public:
explicit QRightClickableTableView(QWidget *parent = 0): QTableView(parent) {}
private slots:
void mouseReleaseEvent(QMouseEvent *e) {
if(e->button()==Qt::RightButton)
emit rightClicked();
else if (e->button()==Qt::LeftButton)
emit leftClicked();
}
signals:
void rightClicked();
void leftClicked();
};
当绑定QRightClickableTableView的selectionChanged信号时,却出现错误。在.cpp文件中:
QRightClickableTableView *table = ui->dataTableView;
connect(table, SIGNAL(leftClicked()), this, SLOT(on_tableViewLeftClicked()));
connect(table, SIGNAL(rightClicked()), this, SLOT(on_tableViewRightClicked()));
connect(table->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
SLOT(on_tableViewSelectionChanged(QItemSelection)));
table->setModel(model);
左击和右击信号按预期工作,但我收到错误提示:
QObject::connect: Cannot connect (null)::selectionChanged(QItemSelection, QItemSelection) to MyApp::on_tableViewSelectionChanged(QItemSelection)