[Interest] Awkward Javascript problem

Mark Tucker mark.tucker at airborne.aero
Thu Nov 30 12:11:49 CET 2017


Hi Nuno,

Are you attempting to access this "controller" property within a "Component.onCompleted" block of code?

With Loaders I've found from experience that there's a brief period of time where the component has been created (and therefore its Component.onCompleted signal fires), but it has not yet been fully added to the object heirarchy, so attempting to access anything outside of that object's own scope fails.

The only way I've ever found to get around this limitation is to instead figure out a way of using the onLoaded signal from the Loader, which seems to be emitted at a point where the QML object is correctly placed within the object heirarchy and can actually correctly access things outside of its own scope.

The above is my own observations from a number of years of writing QML code - it may be what you're seeing here. I don't know anywhere near enough about how the C++ side of things or how the internals of Qt works to be able to provide any more detail.

Perhaps you can change the point at which you run this code?

Mark T

From: Interest [mailto:interest-bounces+mark.tucker=airborne.aero at qt-project.org] On Behalf Of Nuno Santos
Sent: 30 November 2017 10:11
To: Qt Project MailingList <interest at qt-project.org>
Subject: [Interest] Awkward Javascript problem

Hi,

I usually register a controller property that points to a Controller classe when I start my Qt apps. I can then access the controller from any point of the code in Javascript:

quickView->rootContext()->setContextProperty("controller", &controller);

Curiously, I’m having an issue in which inside a MouseArea onClick event, controller is not defined:

ReferenceError: controller is not defined

This MouseArea lives inside a Loader component that is one of the children of a SplitView.

Maybe this be the cause for such ReferenceError? How can I workaround this? Any ideas?

Thanks!

Regards,

Nuno


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20171130/6586726d/attachment.html>


More information about the Interest mailing list