Delegates and Instantiator problem.



  • 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.


Log in to reply
 

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