[Qt5-feedback] C++ api to use for UI in addition to QML
Stefan Majewsky
stefan.majewsky at googlemail.com
Wed May 18 23:27:46 CEST 2011
On Mon, May 16, 2011 at 10:58 PM, Alan Ezust <alan.ezust at gmail.com> wrote:
> in QML 1.x, you can set
> objectName: "someObjectName"
> on any QML Item and then use
> QObject::findChild<QDeclarativeItem*>("someObjectName")
> to find it.
This approach breaks when lists of objects are created from a template
declaration, e.g. in Repeater.
Given that Qt people insist on the API/ABI compatibility argument (and
that's indeed a very strong and understandable one!), what people are
really begging for IMO is a simple API for accessing QObjects inside a
QtDeclarative object tree. Something like
> qmlContext.get("someObjectName")["width"] = 100;
This should be doable efficiently with very little template magic,
where "efficiently" means "effectively no overhead over the explicit
code":
> QObject* obj = qmlContext.rootObject()->findChild<QWhatEver*>("someObjectName");
> obj->setProperty("width", qVariantFromValue<int>(100));
Plus it would be a strong motivation for the bindings developers to do
something similar in the bindings, like in Python:
> qmlContext.someObjectName.width = 100
Greetings
Stefan
P.S. The fine print: Dunno if QDecl.Context is the right place for
this. Also don't count on the correctness of every single word of
code; it's too late here.
More information about the Qt5-feedback
mailing list