[Qt5-feedback] C++ api to use for UI in addition to QML

Alan Alpert alan.alpert at nokia.com
Thu May 19 02:00:40 CEST 2011


On Thu, 19 May 2011 07:27:46 ext Stefan Majewsky wrote:
> 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.

Actually, it only breaks if you try to use ids as the object name. Because 
objectName is just a string, you can dynamically create a new one for each 
element. For example
Repeater{
	model: 5
	Item{
		id: container
		objectName: "Item" + modelIndex;
	}
}

> 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

We already have bindings that allow you to, from the same context, just write 
'someObjectName.width = 100'. These bindings are called QML. This really 
sounds like trying to solve the same problem that QML solves already.

-- 
Alan Alpert
Senior Engineer
Nokia, Qt Development Frameworks


More information about the Qt5-feedback mailing list