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: 338
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook

Signal in WeatherGuesserApp

There is a signal in the WeatherGuesserApp example that I am trying to userstand. The signal is onCityChanged in WeatherPage.qml. For the life of me I can figure out where the qml file(s) know that this signal has been declared. When I do something similar in my example, it tells me it is an unknown signal. If I comment out everything in the WeatherGuesserApp that deals with the signal in the hpp/cpp files, the IDE doesn't complain about the onCityChanged signal. Can someone please clarify how and where this signal is declared and visible to the QML code?

 

 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Signal in WeatherGuesserApp

There's a bit of magic.

There's a global registry of signals, maintained by Qt, and it holds the name and signature of the signal after it's defined by the registration of the WeatherModel class (see weathermodel.h for the "cityChanged" signal).

Then there's the fact that defining handlers of the form "onSomeSignal" in QML automatically connects them as slots to the corresponding signal named "someSignal", complete with the capitalization differences you see there.

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!
Developer
Posts: 338
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook

Re: Signal in WeatherGuesserApp

That is what I thought, but in my other posting,

 

http://supportforums.blackberry.com/t5/Cascades-Development/Activity-Indicator-Signals-and-C/td-p/20...

 

This defining doesn't seem to work. It gives me an unknown signal error. When I comment out everything in the WeatherGuesserApp other than the onCityChanged in QML and signals: void cityChanged(QString city); I don't get the same error in QML. What am I missing?

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Signal in WeatherGuesserApp

Oh, I guess the "automatic connection" I mentioned works only with signals defined in the QML as well.

 

Notice that the WeatherPage defined in main.qml has a "city" property, bound to  _homeModel.city.  That _homeModel is set from a setContextProperty() in the c++ code, and the "city" property is defined as Q_PROPERTY(QString city READ city WRITE setCity NOTIFY cityChanged).  That lets the QML code set up the binding, I believe.


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!
Developer
Posts: 338
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook

Re: Signal in WeatherGuesserApp

If I comment out the Q_PROPERTY, it doesn't complain about it when compiling like in the example I posted. That is what I can't figure out.

BlackBerry Development Advisor
Posts: 252
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10
My Carrier: Bell

Re: Signal in WeatherGuesserApp

[ Edited ]

Hi Bluenoser,

 

In order to expose C++ objects to QML you need to define a Q_PROPERY macro in the header of your HTTRead class.

 

For more information on how to expose C++ objects to QML, you can have a look at this part of the Cascades documenatiation: https://developer.blackberry.com/cascades/documentation/dev/integrating_cpp_qml/

 

For more information on how to use the Qt property system, you can refer to the following documentation:

https://developer.blackberry.com/cascades/reference/properties.html#qt-s-property-system

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker