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
drPetr007
Posts: 48
Registered: ‎10-11-2012
My Device: Z10
Accepted Solution

How to return bb::cascades::Control object from QML to C++ as property ?

Hi all,

 

I need to return value of QML property to C++, problem is that this value is bb::cascades::Control object

Look at the sample :

import bb.cascades 1.2

Page {
 property NavigationPane currentNavigationPane: tab1.navHandle
 property int testprop:0
}

 In C++ I need to retrieve currentNavigationPane property value (I guess it must pointing to NavigationPane *)

		QVariant const   prop=__current_page->property("currentNavigationPane");
		NavigationPane* nav_p=prop.value<NavigationPane*>();
		if (nav_p!=NULL){
			qDebug()<<"nav_p is not NULL";
		}
		qDebug()<<prop.typeName();

 As result of this code : nav_p is null pointer and app is crashing without any debug notes on qDebug()<<prop.typeName();

 

Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: How to return bb::cascades::Control object from QML to C++ as property ?

You wouldn't normally pass around pointers between C++ and QML instead you should use signals and slots or at a pinch use findChild to access the object by name.


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

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
drPetr007
Posts: 48
Registered: ‎10-11-2012
My Device: Z10

Re: How to return bb::cascades::Control object from QML to C++ as property ?

I found solution by exposing c++ class into QML and I can call it's methods with pointer to bb::cascades::Control as parameter

QML

Page {
id:this_page
    onCreationCompleted: {
        mainCPP.UpdatePage(this_page);
    }
}

 C++

Q_INVOKABLE void UpdatePage(bb::cascades::Page *call_back_page){
if(call_back_page){
qDebug()<<"Page is valid";
}
}

 By this method I can use Cascade's control in C++

 

Please use plain text.
Retired
robbieDubya
Posts: 418
Registered: ‎07-18-2012
My Device: Q10

Re: How to return bb::cascades::Control object from QML to C++ as property ?

Your original approach will work with most classes.

 

However - just try doing a qDebug() << theProperty and you'll see that a NavigationPane in QML is a actually a QmlNavigationPane. These aren't the exact same type and QVariant doesn't let you get the raw pointer out and doesn't let you extract based on inheritence - meaning no matter what you ask for (eg: QObject*, void*) you're going to get NULL back out of the variant.

 

(I don't know why there is an undocumented QmlNavigationPane class...)

--
Rob is no longer associated with BlackBerry.
Please use plain text.