mercredi 17 avril 2019

Using lambda syntax in Qt signal and slot and accessing passed arguments

I have a class that has a signal with this signature:

// CLASS A
signals:
    void requestToChangeRange(voltage_range_e vr, current_range_e cr, uint16_t bits);

There is another class which has a slot like this (notice the extra parameter)

// CLASS C
public slots:
    void requestToChangeRange(voltage_range_e vr, current_range_e cr, uint16_t bits, uint16_t limiter);

Then I have a class "B" which acts as a meeting point of all other classes. When the class "A" emits the signal, class "C" should redirect it into class "B". But thtat extra argument on the slot of class "B" is the problem, because that extra argument comes from another class "X".

So If the signal and slots of classes "A" and "C" were matching I would to in class "B" the following:

// somewhere in CLASS B (the manager of all other classes)
connect(pClassA, &ClassA::requestToChangeRange,
    pClassC, &ClassC::handleRequestRangeChange);

But obviously this does not work because of funtion signatures. What I want to do is something like:

// somewhere in CLASS B (the manager of all other classes)
connect(pClassA, &ClassA::requestToChangeRange,
this /* class B */, []() {
    // Get that last required parameter from class X
    uint16_t limiter = pClassX->getValue();
    // Call slot of class C
    pClassC->handleRequestRangeChange(vr, cr, bits, limiter);
});

So how can I access those passed parameters inside the lambda. Is this even possible?

Aucun commentaire:

Enregistrer un commentaire