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
New Contributor
Posts: 9
Registered: ‎07-12-2013
My Device: z10,q10
My Carrier: fdf

Issue in assignment from jsobject to Q_PROPERTY

Hi,

    As per my requirement,trying to assign jsobject from js file to Q_PROPETY of cpp side.But it's getting crashed in my application.Here Q_PROPERTY taking as QVariant type but it's not working as per expected.

 

Here i am giving some code snippet in below for more info.

   

//mycpp.cpp file

  Q_PROPERTY(QVariant onSelection READ onSelection WRITE setOnSelection NOTIFY onSelectionChanged)

//myjs.js file

function onSelection() {
    console.log("Listbox on selection changed");
}

function frmHome_btn_onClick_seq0(eventobject) {
   mycpp.onSelection = onSelection;//--this point crashed.

Note:--If i made it(onSelection method) as Q_INVOKABLE slot then it's working fine but as per requirement it should be Q_PROPERTY.
};

 

Any help would be much appreciated.

 

Thanks in advance

sk

Highlighted
Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Issue in assignment from jsobject to Q_PROPERTY

Do you have a setOnSelection function? You need that. Also, why is the property called "onSelection"? That sounds a lot like a signal.

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
New Contributor
Posts: 9
Registered: ‎07-12-2013
My Device: z10,q10
My Carrier: fdf

Re: Issue in assignment from jsobject to Q_PROPERTY

Hi ,

Thanks for reply.yes i have setOnselection method.Though it seems like predefined signal but It's my own defined property.Apart from jsobject if i assign anything else(interger,string...) it's working fine.

 

Thanks

Sk

Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Issue in assignment from jsobject to Q_PROPERTY

What kind of object does your setOnSelection method accept? And how does it not work? Is the method getting called? What are you trying to pass in?

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
New Contributor
Posts: 9
Registered: ‎07-12-2013
My Device: z10,q10
My Carrier: fdf

Re: Issue in assignment from jsobject to Q_PROPERTY

[ Edited ]

Hi Paul,

Thanks for reply.

      In Qt property, trying to assign values either some string or object.All taking as QVariant type  in qt side.Please find the below given examples on js assignment to qt property.Please let me know if you need more details.

 

Case -1:-

//Js FIle

function MyMethod() {

}

 

MyObj.onSelection = MyMethod(JsObject)--->here crashing --setOnselection method of cpp side not calling--Control not going to cpp side.It's crashing here only.

[In cpp side this js object is nothing but --- QVariant(QVariantMap, QMap(("arguments", QVariant(, ) ) ( "callee" ,  QVariant(, ) ) ( "caller" ,  QVariant(, ) ) ( "length" ,  QVariant(int, 0) ) ( "name" ,  QVariant(QString, "MyMethod") ) )  ) ]

 

Case -2:--

MyObj.onSelection = "test"--->Working Fine

[In cpp side this js string is nothing but --- QVariant(QString, "test") ]

 


Note:--If i call setOnselection(MyMethod) function directly then it's working fine but in case of property no need to call directly the function(setOnselection) rather it sould call implicity when we assign some value to property(onselection).

 

Thanks & Regards,

Skbb