Is it possible to emit a signal from an QML ListModel element?



  • My idea is to define a ListModel with some Elements, like this.

    @
    ListModel {
    id: list

    ListElement {
    name: "test"
    signal run
    }

    ListElement {
    name: "second"
    signal stop
    }

    ListElement {
    ...
    }
    }@

    Then I want to connect the Signal run with a State and start the Signal in Javascript with (for Example)

    @emit ListView.currentItem.signal@

    Thank you for your help.



  • Hello,
    It should work with:
    @
    ListView.currentItem.run();
    @

    (Which is the correct syntax provided currentItem has run signal and you call it from ListView's scope)



  • Hello,

    thank you for your answer.

    My problem is, that i want to define a signal for each ListElement and then call the signal from the current item and not an specific.

    I edited the code above, so you can see that every ListElement has it's own signal.



  • Hello,
    What I proposed will work if all your signals have the same name (which is no your case).
    You will have to find what kind of signals are present for currentItem and call the signal you need to call.
    I don't know if there is a means to get the list of signals of an object at runtime from QML.
    Good luck!


Log in to reply
 

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