2017-04-03 75 views
0

我想將參數傳遞到選擇傳遞參數改變SLOT類似如下:Qt的:在的SelectionChanged()信號

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

我想在SLOT中使用MyParameter。有沒有辦法做到這一點?是否有可能建立一個自定義selectionChanged()信號?

回答

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

它不工作的代碼。這只是解釋你如何做到這一點。