我想将参数传递给选择更改的SLOT,如下所示:
connect(selectionModel, SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &, MyParameter)),
this, SLOT(OnSelection(const QItemSelection &, const QItemSelection &, MyParameter)));
或者至少喜欢:
connect(selectionModel, SIGNAL(selectionChanged (MyParameter)),
this, SLOT(OnSelection(MyParameter)));
我想使用MyParameter
中的SLOT
。有办法吗?是否可以构建自定义selectionChanged()
信号?
答案 0 :(得分:0)
您可以从selectionModel
类继承并使用所需参数实现自己的信号。然后创建一个连接到默认信号的插槽,并在其中收集参数并发出信号。
像这样:
MySelectionModel: public SelectionModel{
public:
MySelectionModel(){
connect(this,
SIGNAL(selectionChanged(const QItemSelection & , const QItemSelection & )),
this,
SLOT(myPrivateSlot(const QItemSelection & , const QItemSelection & )));
}
private slots:
void myPrivateSlot(const QItemSelection & selected, const QItemSelection & deselected){
//collect or calculate params you want
emit mySignal(selected, deselected, yourParams);
}
signals:
void mySignal(const QItemSelection & selected, const QItemSelection & deselected, MyParams params);
}
这不是代码。它只是解释你如何做到这一点。