QTableView selectionChanged

扶醉桌前 提交于 2019-12-10 12:46:24

问题


I have a QTableView that I need to get the selectionChanged event from. I can't seem to get the connect working. I have:

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))
 );

...

At runtime, I get "No such Signal" errors.


回答1:


You need to remove the variable names from the SIGNAL and SLOT macros:

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

Connect is essentially looking at the function signature and the variable names confuse it.



来源:https://stackoverflow.com/questions/2376052/qtableview-selectionchanged

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!