0

I want to pass a parameter to the selection changed SLOT like the following:

connect(selectionModel, SIGNAL(selectionChanged (const QItemSelection &, const QItemSelection &, MyParameter)),
    this, SLOT(OnSelection(const QItemSelection &, const QItemSelection &, MyParameter)));

Or at least like:

connect(selectionModel, SIGNAL(selectionChanged (MyParameter)),
    this, SLOT(OnSelection(MyParameter)));

I want to use the MyParameter in the SLOT. Is there a way to do it? Is it possible to build a custom selectionChanged() Signal?

m0nhawk
  • 22,980
  • 9
  • 45
  • 73
Khaled
  • 59
  • 1
  • 12

1 Answers1

0

You can inherit from your selectionModel class and implement its own signal with the required parameters. Then create a slot that connects to the default signal, and in which to collect the parameters and emit your signal.

Like this:

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

It is not working code. It is just explain how you can done it.

Konstantin T.
  • 994
  • 8
  • 22