我有一个 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))
);
...
在运行时,我收到“没有这样的信号”错误。
最佳答案
您需要从 SIGNAL 和 SLOT 宏中删除变量名称:
connect(
table->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
SLOT(slotLoadTransaction(const QItemSelection &, const QItemSelection &))
);
Connect 本质上是查看函数签名,而变量名称会混淆它。
关于QTableView selectionChanged,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2376052/