[Interest] binding two QML object within C++

Alex Montgomery apmontgomery at gmail.com
Thu May 29 21:35:11 CEST 2014


Hello,

I'm trying to do something that seems very simple, but I can't find a
solution anywhere. If I have two QML items that I've created from
components in C++, how do I bind a property on one to follow a property on
the other one? Here's a simple example:

// Simple.qml
Rectangle
{
   property bool myBool : false
}

// C++ code
QQmlComponent simpleFactory;
simpleFactory.loadUrl(QUrl("qrc:///Qml/Simple.qml"));
QQuickItem* item1 = qobject_cast<QQuickItem*>(m_simpleFactory.create());
QQuickItem* item2 = qobject_cast<QQuickItem*>(m_simpleFactory.create());

// how do I bind item2's myBool to the value of item1's myBool?

This is very simply done within QML, but I don't see how to do that glue in
C++.

Any help would be appreciated,
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140529/57d2261d/attachment.html>


More information about the Interest mailing list