PDA

View Full Version : Warnings when creating embedded Menus with Instantiator



ribtoks
9th February 2016, 12:05
I'd like to create a Menu in QML application that has other Menus depending on some Model. When I use Instantiator for that, items which are being created are parented to the Instantiator itself and when adding them to top-level Menu, it complains about `__parentMenu` being null


Menu {
title: qsTr("Top-Level Menu")
id: topMenu

Instantiator {
model: aTopLevelModel
onObjectAdded: topMenu.insertItem( index, object )
onObjectRemoved: topMenu.removeItem( object )

delegate: Menu {
id: innerMenu
title: qsTr("Inner Menu")

Instantiator {
model: aTopLevelModel.getInnerModel(index)
onObjectAdded: innerMenu.insertItem( index, object )
onObjectRemoved: innerMenu.removeItem( object )

delegate: MenuItem {
text: qsTr("Menu action!")
onTriggered: {
console.log("Action of inner menu")
}
}
}
}
}
}
The warning I'm observing is:

Menu.qml:149: TypeError: Cannot read property '__contentItem' of null
Where the line 149 is

property var __parentContentItem: __parentMenu.__contentItem
How can I overcome this Warning being produced?

Qt version is 5.5.1. This behavior is observed undre OS X and Windows versions of Qt.

anda_skoa
9th February 2016, 12:22
I guess the only way to fix this is in Menu.qml

That line needs to be something like


property var __parentContentItem: __parentMenu ? __parentMenu.__contentItem : null


Cheers,
_

ribtoks
9th February 2016, 12:30
Should I then send my edits to Qt repo? I mean, officially I would patch Qt, so I would need to ship modified Qt and all that stuff with licenses, you know..

anda_skoa
9th February 2016, 13:41
If you can verify that this fixes the problem, it would be great is this would end up in Qt proper.
First step for that is to create a ticket at https://bugreports.qt.io/secure/Dashboard.jspa ideally with a test case that shows the problem.

For you locally it depends on the license you are using Qt with.

The commerical license doesn't require you to ship any source, the open source license already require you to make the sources of Qt available to whoever you distribute the software to.

Cheers,
_

ribtoks
9th February 2016, 13:43
The OpenSource License doesn't require me to ship Qt if I didn't modify it.
Yes, I'll create a bug. Thank you.

anda_skoa
9th February 2016, 14:11
The OpenSource License doesn't require me to ship Qt if I didn't modify it.

Right, you can also offer a download of the Qt code.
In case of a modifcation you would need to offer download of your modifed source instead of just having the official Qt sources mirrored.

Cheers,
_