Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Is it possible to emit a signal from an QML ListModel element?

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

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 1 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • U Offline
      U Offline
      unai_i
      wrote on last edited by
      #2

      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)

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • U Offline
          U Offline
          unai_i
          wrote on last edited by
          #4

          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!

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved