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. Difference between Repeater and Instantiator
Forum Updated to NodeBB v4.3 + New Features

Difference between Repeater and Instantiator

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 2.5k Views 2 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.
  • S Offline
    S Offline
    sandro4912
    wrote on last edited by
    #1

    What is the difference between Repeater and Instantiator?

    For Repeater it says:

    Instantiates a number of Item-based components using a provided model

    For Instantiator it says:

    A Instantiator can be used to control the dynamic creation of objects, or to dynamically create multiple objects from a template.

    But ins't that the same?

    Is the Instantiator even ever used nowadays. I couldn't find good examples.

    1 Reply Last reply
    0
    • GrecKoG Online
      GrecKoG Online
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      Repeater only work with Item delegates and it parents the delegate it creates to the Repeater's parent item.
      Instantiator work with every objects.

      S 1 Reply Last reply
      4
      • GrecKoG GrecKo

        Repeater only work with Item delegates and it parents the delegate it creates to the Repeater's parent item.
        Instantiator work with every objects.

        S Offline
        S Offline
        sandro4912
        wrote on last edited by
        #3

        @GrecKo

        So that means with Instantiator I have to parent the items myself after?

        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

          Both types have signals that get called when items/objects are created. You can use these signals to insert/remove the items/objects. I use Instantiators when I want precise control of parenting via a function that I call to determine the parenting. I also use Instantiators to create non-Item objects. For instance you can create Emitters for particles on the fly this way. I have found Repeaters useful for creating MenuItems for Menus for things like file history.

          C++ is a perfectly valid school of magic.

          S 1 Reply Last reply
          3
          • fcarneyF fcarney

            Both types have signals that get called when items/objects are created. You can use these signals to insert/remove the items/objects. I use Instantiators when I want precise control of parenting via a function that I call to determine the parenting. I also use Instantiators to create non-Item objects. For instance you can create Emitters for particles on the fly this way. I have found Repeaters useful for creating MenuItems for Menus for things like file history.

            S Offline
            S Offline
            sandro4912
            wrote on last edited by
            #5

            @fcarney Thanks for the explanation. I wasn't thinking about stuff like Emitter to create dynamically.

            So the main differences are:

            Repeater:

            Can only create Item based elements dynamically

            Parenting happens automatically for created elements.

            Instantiator:

            Can create "all" Elements dynamically.

            Created elements have to be parented manually.

            Which library do you have to import to use Instantiator? I tried to use import QtQml 2.2 like the docs say but than it says "Unknown component".

            1 Reply Last reply
            0
            • fcarneyF Offline
              fcarneyF Offline
              fcarney
              wrote on last edited by
              #6

              @sandro4912 said in Difference between Repeater and Instantiator:

              Which library do you have to import to use Instantiator?

              https://doc.qt.io/qt-5/qml-qtqml-models-instantiator.html
              At the top of page it says the import. Also, searching "qml instantiator" will find that page.

              C++ is a perfectly valid school of magic.

              1 Reply Last reply
              1

              • Login

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