QTableView selectionChanged

时间:2010-03-04 00:18:43

标签: qt qt4 selection

我需要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”错误。

1 个答案:

答案 0 :(得分:16)

您需要从SIGNAL和SLOT宏中删除变量名称:

 connect(
  table->selectionModel(),
  SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
  SLOT(slotLoadTransaction(const QItemSelection &, const QItemSelection &))
 );

Connect实际上是在查看函数签名,变量名称会使它混淆。

相关问题