Hi Rene,

I'll let for others to give more implementation detail on that since I'm not
very familiar with the code.

Meanwhile, may I ask you the rationale behind that? If the purpose is just
to set a text label from C++ to Quick, the thing is Quick was thought of
with an "upside-down" concept in mind.

IOW, the QML elements should "pull" this information from C++ rather than
C++ trying to "push" that inside QML elements. Arguably this keeps a better
conceptual separation between C++ and QML in the sense it avoids C++ code to
assume things about the structure of QML and its elements IDs.

So you could augment the QML context with a property holding a reference to
a QObject of yours, and then in QML you would do:

Rectangle {
    Rectangle {
        Text {
            text: dataSource.text
        }
    }
}

Where "dataSource" is the name of the property holding the QObject
reference.

Then from C++ you just do:

objectVisibleToQML->setText("Hello World!");

Assuming objectVisibleToQML is implemented with propert NOTIFY signals, the
Label will be updated accordingly.

Also, if tomorrow someone decides this label should be moved to the top of
the screen, and get out of the Rectangle, it still works. Also, if you
decide you should add another label showing the same text, it also works.
That's the idea of avoiding traversing the QML item tree from C++.

But again, maybe you're trying to do something more specific, if so, please
disregard what I just said :-P

Cheers,
Eduardo

On Thu, Nov 4, 2010 at 9:26 AM, René Hansen <ext-rene.1.han...@nokia.com>wrote:

> I'd like to be able to find child objects in a QML structure and to do
> that, I've exposed a new QML Object with qmlRegisterType, which provides
> me with:
>
> QObject *QmlUnitTestHelper::getChildById(QObject *parent, QString name) {
>        return parent->findChild<QObject *>(name);
> }
>
> And in Qml I have something like this:
>
> Rectangle {
>
>        QmlUnitTestHelper {
>                id: quth
>        }
>
>        Rectangle {
>                id:outerRect
>                Rectangle {
>                id:innerRect
>                Text {
>                        id:label
>                        text: "Hello World"
>                }
>        }
>        }
> }
>
> Which should enable me to test in something like this manner:
>
> quth.getChildById(outerRect, "innerRect").label.text == "Hello World"
>
> However, this doesn't work as expected, so I guess my assuming the QML
> id property being the same as a QObjects objectName is faulty.
>
> How would I go about doing something like this?
>
> /René
>
>
>
> _______________________________________________
> Qt-qml mailing list
> Qt-qml@trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-qml
>



-- 
Eduardo M. Fleury
OpenBossa - INdT
http://eduardofleury.com/
http://www.openbossa.org/
_______________________________________________
Qt-qml mailing list
Qt-qml@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-qml

Reply via email to