[Interest] Finding the root QQuickItem in a QQml(Application)Engine

Ben Lau xbenlau at gmail.com
Mon May 11 17:47:36 CEST 2015


On 11 May 2015 at 21:06, Sze Howe Koh <szehowe.koh at gmail.com> wrote:

> Hello,
>
> Is there an analogue of QQuickView::rootItem() for QQml(Application)Engine?
>
> The shortest way I could think of involves jumping through a few hoops,
> e.g.:
>
>     QQmlApplicationEngine engine;
>     // ...
>     auto window = engine.rootObjects().first();
>     auto aQuickItem =
> qobject_cast<QQuickItem*>(window->children().first());
>     auto rootItem = aQuickItem->parentItem();
>
>
> Regards,
> Sze-Howe
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
Hi,

I use this piece of code to find the root QQuickItem (part of my test
suite):

    engine.load(url);

    QObject *rootObject = engine.rootObjects().first();


    QQuickWindow *window = qobject_cast<QQuickWindow*>(rootObject);

    if (window) {

        setTestableRootObject(window->children().first());

    } else {

        setTestableRootObject(rootObject);

    }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150511/ad32f088/attachment.html>


More information about the Interest mailing list