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. Access function/slot loader element in listview
QtWS25 Last Chance

Access function/slot loader element in listview

Scheduled Pinned Locked Moved Solved QML and Qt Quick
listviewloaderfunction
4 Posts 3 Posters 945 Views
  • 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.
  • D Offline
    D Offline
    Delta_sim
    wrote on 29 Nov 2018, 11:32 last edited by
    #1

    Hello,

    I would like to know if it's possible to call a function in component loaded in listview.
    Let me explain :

    I have a main.qml file with a Lisview to display my application pages :

    //main.qml
    ListView {
            id:myListView
            anchors.fill: parent
            orientation: ListView.Horizontal
            cacheBuffer: main.width * (NbPages-1) 
            model: PageNames
            delegate: Loader {
                id: myLoader
                source: modelData + ".qml"
            }
        }
    

    And in every item of "modelData " I have a function called "cyclicActions"

    //page1.qml
    function cyclicActions()
    {
       ----
    }
    
    //page2.qml
    function cyclicActions()
    {
       ----
    }
    

    So I want to call cyclicActions only for the currentItem of the Listview.
    I saw ListView.currentItem method but I can't access to the function.

    Can you help me with that ?

    Than you

    S R 2 Replies Last reply 29 Nov 2018, 11:36
    0
    • D Delta_sim
      29 Nov 2018, 11:32

      Hello,

      I would like to know if it's possible to call a function in component loaded in listview.
      Let me explain :

      I have a main.qml file with a Lisview to display my application pages :

      //main.qml
      ListView {
              id:myListView
              anchors.fill: parent
              orientation: ListView.Horizontal
              cacheBuffer: main.width * (NbPages-1) 
              model: PageNames
              delegate: Loader {
                  id: myLoader
                  source: modelData + ".qml"
              }
          }
      

      And in every item of "modelData " I have a function called "cyclicActions"

      //page1.qml
      function cyclicActions()
      {
         ----
      }
      
      //page2.qml
      function cyclicActions()
      {
         ----
      }
      

      So I want to call cyclicActions only for the currentItem of the Listview.
      I saw ListView.currentItem method but I can't access to the function.

      Can you help me with that ?

      Than you

      S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 29 Nov 2018, 11:36 last edited by
      #2

      @Delta_sim said in Access function/slot loader element in listview:

      I saw ListView.currentItem method but I can't access to the function.

      How did you try to access it?

      In general, something like this might work:

      // Some JS block:
      myListView.currentItem.item.cyclicActions()
      

      (Z(:^

      1 Reply Last reply
      2
      • D Delta_sim
        29 Nov 2018, 11:32

        Hello,

        I would like to know if it's possible to call a function in component loaded in listview.
        Let me explain :

        I have a main.qml file with a Lisview to display my application pages :

        //main.qml
        ListView {
                id:myListView
                anchors.fill: parent
                orientation: ListView.Horizontal
                cacheBuffer: main.width * (NbPages-1) 
                model: PageNames
                delegate: Loader {
                    id: myLoader
                    source: modelData + ".qml"
                }
            }
        

        And in every item of "modelData " I have a function called "cyclicActions"

        //page1.qml
        function cyclicActions()
        {
           ----
        }
        
        //page2.qml
        function cyclicActions()
        {
           ----
        }
        

        So I want to call cyclicActions only for the currentItem of the Listview.
        I saw ListView.currentItem method but I can't access to the function.

        Can you help me with that ?

        Than you

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 29 Nov 2018, 11:49 last edited by
        #3

        @Delta_sim said in Access function/slot loader element in listview:

        I saw ListView.currentItem method but I can't access to the function.

        as @sierdzio said.
        If you call your method on listView.currentItem directly you are actually calling it on the Loader item

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Delta_sim
          wrote on 29 Nov 2018, 12:09 last edited by
          #4

          Indeed it works !
          I did 2 mistakes, I forgot ".item" after currentItem and I didn't changed currentIndex when I switch between pages because I use positionViewAtIndex. But positionViewAtIndex don't change currentIndex of the listView.

          Thanks guys !

          1 Reply Last reply
          0

          4/4

          29 Nov 2018, 12:09

          • Login

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