[Interest] When is parent not the parent?

Jérôme Godbout godboutj at amotus.ca
Thu Dec 12 15:38:29 CET 2019


Quick question (punt intendended), why using Screen as object and not a Window element? Screen is an Attachement Object normally and therefore should not have children, it should not be used that way unless I'm missing something here, your Screen is the 
https://doc.qt.io/qt-5/qml-qtquick-window-screen.html

This is also going to happen when the Item have the default as an alias to sub children and this make perfect sense on some Items. You should use the id directly, it will be more robust and striaght forward. They all have parent, since they are all (except basic type) QObject. The parent might just not what it seem on the first look, but the real parent is necessary for proper scaling sometime!

-----Original Message-----
From: Interest <interest-bounces at qt-project.org> On Behalf Of Jason H
Sent: December 11, 2019 6:05 PM
To: interestqt-project.org <interest at qt-project.org>
Subject: [Interest] When is parent not the parent?

A simple Screen item derived from Item whose visible is false:

Screen {
	id: proxScreen
	property int distanceEvents: 0
	property string lastValue: "Far"

	ProximitySensor {
		id: proximity
		active:parent.visible
	}
}

When I change the line:
    active: parent.visible
to:
    active: proxScreen.visible

The behavior changes. When it is referencing it as parent, the proximity sensor is active. When I use proxScreen instead, it is not active.
"
Reading up on this, it seems to be because parent refers only to the "visual parent". Which, I think is fine. The parent of the ProximitySensor is an Item, it has a visual parent. However this doesn't seem to be the case because ProximitySensor is not an Item itself so regardless of it's parent being a "visual parent". Therefore the docs are wrong, misleading or confusing.

How much would it break things of we just made everything that is a child of something have a parent? I think it's completely reasonable to say (as I attempted to above) that this thins is only active when its parent is visible. I don't know how or what was being resolved as it's parent. I would have expected a "property not found" error or something, but I didn't get that.

Given this kind of error, I suggest we just let everything have a parent, visual or not. It's unnatural to have so many things have a parent, and some others not.

Thoughts?



_______________________________________________
Interest mailing list
Interest at qt-project.org
https://lists.qt-project.org/listinfo/interest


More information about the Interest mailing list