Connecting C++ signal to QML function with arguments



  • Connecting a C++ signal to a QML function seems to work fine if the QML function has no arguments.
    But if the QML function has an argument, how can I connect a signal to it? What is the type of the argument? QVariant?



  • name the parameters in your signal declaration, something like this

    @void mySignal(int value);@

    and you can get the parameter value by using that name. for example

    @
    connections {
    target: engine

    onMySignal: {
    console.log(value)
    }
    }
    @



  • Thanks. Problem is, I need to connect the signal to the QML function from C++, since I don't know the name of the signal/function to connect until runtime.


Log in to reply
 

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