我需要QTableView
才能从中获取selectionChanged事件。我似乎无法使连接工作。我有:
MyWidget.h
...
protected slots:
void slotLoadTransaction(const QItemSelection & selected, const QItemSelection & deselected);
private:
QTableView table;
...
MyWidget.cpp
...
connect(
table->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection & selected, const QItemSelection & deselected)),
this,
SLOT(slotLoadTransaction(const QItemSelection & selected, const QItemSelection & deselected))
);
...
在运行时,我收到“No such Signal”错误。
答案 0 :(得分:16)
您需要从SIGNAL和SLOT宏中删除变量名称:
connect(
table->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
SLOT(slotLoadTransaction(const QItemSelection &, const QItemSelection &))
);
Connect实际上是在查看函数签名,变量名称会使它混淆。