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
Posts: 65
Registered: ‎03-20-2013
My Device: Z10(Red Limited Edition)
My Carrier: MY COMPANY

anyway to connect QML signals to cpp slot .

Is there anyway to connect QML signals to cpp slot.

 

Thanks,

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: anyway to connect QML signals to cpp slot .

[ Edited ]

Yes use connect.

Of course your c++ class needs to be visible to the QML object.

 

Take a look at the bottom section substitute the JavaScript function for your C++ object's slot...

 

http://developer.blackberry.com/native/documentation/cascades/dev/javascript/


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Highlighted
Developer
Posts: 136
Registered: ‎01-25-2010
My Device: Z30, Z10, Q10, Dev Alpha B & Bold 9900
My Carrier: Bell

Re: anyway to connect QML signals to cpp slot .

Connecting to a signal is pretty simple and works great but you might want to look at this thread in regards to disconnecting your signal if required.... Otherwise, you may end up with multiple signal connection and weird behavior...

 

http://supportforums.blackberry.com/t5/Native-Development/signal-not-disconnecting-when-page-is-clos...

New Contributor
Posts: 3
Registered: ‎11-18-2013
My Device: Z10
My Carrier: CNMB

Re: anyway to connect QML signals to cpp slot .

Developer
Posts: 123
Registered: ‎01-11-2013
My Device: BlackBerry z10
My Carrier: Docomo

Re: anyway to connect QML signals to cpp slot .

Hello friend,

Yes you can create function in cpp and call it whenever you emit the signal in qml.

Developer
Developer
Posts: 132
Registered: ‎01-24-2013
My Device: blackberry z10
My Carrier: none

Re: anyway to connect QML signals to cpp slot .

[ Edited ]

You dont have to do the connecting/disconnecting in qml, you can equally well do it in cpp:

 

QObject * MyButton = root->findChild<QObject*>("mybutton");
if(!MyButton)
   warneMePlease();
connect(MyButton, SIGNAL(mySig()), this, SLOT(mySlot()));

 

 

 
Its generally better and easier to keep the cpp "in charge" and the qml "unaware" than the other way round.
 
Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: anyway to connect QML signals to cpp slot .


p8 wrote:

You dont have to do the connecting/disconnecting in qml, you can equally well do it in cpp:

 

QObject * MyButton = root->findChild<QObject*>("mybutton");
if(!MyButton)
   warneMePlease();
connect(MyButton, SIGNAL(mySig()), this, SLOT(mySlot()));

 

 

 
Its generally better and easier to keep the cpp "in charge" and the qml "unaware" than the other way round.
 

if creating Pages dynamically in QML you have to disconnect when destroying the page and re-connect after creation

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Developer
Posts: 132
Registered: ‎01-24-2013
My Device: blackberry z10
My Carrier: none

Re: anyway to connect QML signals to cpp slot .

Good point.

However cpp objects could equally well be dynamic and one could also have the reverse problem (qml would be left with a dangling reference), so its not really a pro or con of one or the other approach