Populating Menu through Component
-
wrote on 3 May 2018, 07:28 last edited by levolex 5 Mar 2018, 08:23
Hello,
I've got problems trying to dynamically add menu items through Compopent element. I've tried several different ways (using Component element, creating Component dynamically...), but the only it works was population of Menu using Instantiator, in all other cases new items show memory addresses as a title and onTriggered() slot does nothing.I can modify my code to use model and Instatiator, but I still wonder why it doesn't work through Component or what I'm doing wrong.
Here is my code:
import QtQuick 2.7 import QtQuick.Controls 1.4 import QtQuick.Layouts 1.3 ApplicationWindow { id: mainWindow visible: true menuBar: MenuBar { Menu { id: reportsMenu title: "Reports" } } Component { id: menuItemComp MenuItem { } } Component.onCompleted: { reportsMenu.addItem(menuItemComp.createObject(reportsMenu, { text: "testing" })); } }
-
addItem
takes a string parameter and return a newly createdMenuItem
. -
wrote on 3 May 2018, 08:59 last edited by
@GrecKo said in Populating Menu through Component:
t
You are so right. It was not correct functioning of QtDesigner context help and my inattention. Context help showed me always the article of component from Qt.labs.platform module. Thank you so much.
1/3