How to pass slot as parameter?



  • I don't understand how to do this like for example:

    @void RequestMessage(SLOT *callback)
    {
    callback.Call(data);
    }@

    I want someone to be able to specify a function on which they get the callback.



  • SLOT is a "function":http://qt-project.org/doc/qt-5/signalsandslots.html#slots. It can either member of a class or standalone function.

    If you need to pass a slot to another function then declare that another function with pointer to a slot-function as a parameter and then call that parameter. An example with member function:
    @
    class A
    {
    ...
    public slots:
    void foo(int);
    ...
    };

    void otherFunction(void (A::*param)(int))
    {
    *param(10);
    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.