Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
simon_hain
Posts: 16,004
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany
Accepted Solution

Notify qml from another class

My brain is a bit drained and i can't seem to connect the signals correctly.

 

I have a main application class A.

In this i create main.qml and use setContextProperty to publish a pointer to class B.

I start a process in B by calling B.start() in qml.

When B is finished it emits a signal complete()

 

How can i receive this signal in qml?

Do i have to use Connections?

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
simon_hain
Posts: 16,004
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Notify qml from another class

Connections seems to be QtQuick, so its not available.
Do i have to connect the signal to A cpp where i have a reference to main.qml?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Notify qml from another class

Actually, and surprisingly to me, we can "import QtQuick 1.0" to get access to certain items (the non-visual ones, I assume), including Connections. Stick them in an attachedObjects: [] list and you should be good.  For example:

import QtQuick 1.0
...
SomeControl {
    ...
    attachedObjects: [
        Connections {
            target: Application
            onThumbnail: console.log("** thumbnailed!")
        }
    ]
}

On the other hand, you don't have to use that, since you can just programmatically connect:

import bb.cascades 1.0

SomeControl {
    ...
    function thumbnailed() {
        console.log("** thumbnailed!");
    }

    onCreationCompleted: {
        Application.thumbnail.connect(thumbnailed); 
    }
}

 

I would expect either one to work for your case.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
simon_hain
Posts: 16,004
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Notify qml from another class

Thanks, importing QtQuick works.

I still don't understand the other way around, and i would like to :smileyhappy:
onCreationCompleted is called when the qml is rendered, i guess.
but how do i connect the signal from my class B there?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Notify qml from another class

I think onCreationCompleted is called probably before rendering, but after all the elements are assembled and basically ready for rendering.  It's called (as far as I can see from observation) on the children, the gradually each parent until it hits the root component and calls its onCreationCompleted last.

 

Try this, based on what you described in your first post:

function handleCompleteSignal() {
    console.log("connect() signal emitted from object myB");
}

onCreationCompleted: {
    myB.complete.connect(handleCompleteSignal);
}

If you've put a reference to the B instance with a name of "myB" for the QML, then the above should find it just fine, at least in any non-dynamically loaded QML. I'm not sure about the visibility within dynamically loaded stuff, but I believe the setContextProperty() stuff is probably visible universally.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
simon_hain
Posts: 16,004
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Notify qml from another class

great, that works!
(after resolving a few small issues on other places).

QML is really easy - when you know what you are doing :smileyhappy:
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.