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. Delegates and Instantiator problem.
Qt 6.11 is out! See what's new in the release blog

Delegates and Instantiator problem.

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 836 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.
  • R Offline
    R Offline
    RuneRask
    wrote on last edited by
    #1

    Hey !

    I have a issue figuring out how to dynamically create objects, inside a object of the same type, specifically a menu.
    my code looks something like this:

    // ContextMenu.qml
    @import QtQuick 2.1
    Menu{

    id: mainMenu;
    ListModel{
        id: menuList;
    }
    
    Instantiator{
        id      : menuInstance;
        active  : false;
        model   : menuList;
        delegate : ContextMenu{
            title: model.name;
        }
        onObjectAdded: {
            mainMenu.insertItem(index, object)
        }
    }
    

    }@

    Now, i understand that creating objects, inside of itself will create recursion. However i don't see why it should create any in this case? Are delegates created even when not used? What is the purpose of a Instantiator, if not to only act, when instantiated?

    What i want to do, is to have contextMenu's added to context menu's dynamically, since i have a lot of custom logic and styling going on. - so normal menu's and menuItems wont do.

    So my question is, how can i do this? How can i say, "use this component, but dynamically, don't instantiate it yet"?

    I hope it makes sense hehe.
    Cheers.

    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