Fastest way to interact with QML

  • Hi everyone, I'm having a question regarding interaction between C++ and QML.

    I've a set of button with different click behaviour (one is pulse, one have to switch state, one have to follow press-release action and so on...), and I'm thinking at the best way to set this particular behaviour.

    I know the behaviour on the C++ side of the object, so my question is related to the fasted way (or the best memory-side one) to send the behaviour to the qml-object from c++:

    1. Create a Q_INVOKABLE method that returns the behaviour and then check it everytime I need to do some action on the button (like on the onRelease function)

    2. Sends signal with the expected behaviour from C++ to QML and then elaborate it once received.

    I've to say that my button isn't on the first layer of my qml stack, they are on the second+ layer, so the signal have to pass thru one qml level before reach the elements.

    Any in-depth explanation on how this works?
    Thank you.

  • You could make the behaviour a property on the c++ side, which uses a string. The string could then be used to call a method.
    // qml
    Buttton {
    onPressed: root'handle_' + nativeObject.behaviour

    if behaviour would be 'flash' it would call root.handle_flash() JS function.

Log in to reply

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