How to reference the caller in QML

Is there a way to get the link to the caller in QML? I am looking at something that is equivalent to the 'this' pointer in QML

Example: Say I have a component that serves as a backend for a graphic element, such as a search tool for a video player. This backend will accept current and total video durations as input and periodically provide updates to the graphic search bar. Now, if this backend has a signal handler for a signal that sends current and total durations, it might look something like this:

Connections { target: sender //this onSendSeekUpdate() { //do something } } 

Of course, I assume that this can be implemented in C ++ and then imported into QML. But I'm just wondering if QML supports this? So that I can immediately write such hooks in QML.

+4
source share
1 answer

In QML, you can use any id as a pointer, as well as any property of a derived QObject type, so in your code example we can dynamically change target Connection and use the same var in the signal handler to point to the sender:

 Connections { target: myitem; // change it when you need onMySignal: { target.doSomething(); // just use target here as it points on the listened object // it just like 'sender()' in Qt/C++ } } 

Not sure if that was what you asked for, but I tried to understand your explanation; -)

+4
source

All Articles