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: 367
Registered: ‎11-25-2009
My Device: Not Specified
Accepted Solution

Trouble emitting C++ signal to call a QML slot

[ Edited ]

Hello,

 

I'm having trouble emitting a signal from C++ code to call a slot function in my QML.  What I currently have looks right (as compared to examples I've seen online), but the slot function is never called.  Can anyone see a problem?  Here is my relevant code:

 

applicaitonui.hpp:

class ApplicationUI: public QObject {
Q_OBJECT
public:
	ApplicationUI(bb::cascades::Application *app);

	virtual ~ApplicationUI() {
	}

signals:
	void successfulAuthentication();

private:
	ActivityIndicator *mActivityIndicator;
	QNetworkAccessManager *mNetworkAccessManager;
};

#endif

 applicationui.cpp:

ApplicationUI::ApplicationUI(bb::cascades::Application *app) :
		QObject(app) {

	QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
	qml->setContextProperty("app", this);

	AbstractPane *root = qml->createRootObject<AbstractPane>();

	mActivityIndicator = root->findChild<ActivityIndicator*>("indicator");

	connect(this, SIGNAL(successfulAuthentication()), root,
			SLOT(onSuccessfulAuthentication()));

	// set created root object as a scene
	app->setScene(root);
}

 main.cpp:

...

emit successfulAuthentication();

...

 main.qml:

// Default empty project template
import bb.cascades 1.0
import bb.system 1.0

NavigationPane {
    id: navigationPane
    Page {
        id: loginPage
        Container {
            layout: StackLayout {
                orientation: LayoutOrientation.TopToBottom
            }
            
            ...
        }
    }
    function onSuccessfulAuthentication() {
        console.log("onSuccessfulAuthentication()");
    }
}

 

Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Trouble emitting C++ signal to call a QML slot

[ Edited ]

I'm not sure if it's possible to connect them from C++ side, but in QML you can do something like:

 

NavigationPane {
  onCreationCompleted: {
    app.successfulAuthentication.connect(onSuccessfulAuthentication)

Or use QtQuick 1.0 Connections { } element (it has to be placed in attachedObjects):

http://supportforums.blackberry.com/t5/Cascades-Development/QML-Connections-Element/m-p/2063301#M955...

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Trouble emitting C++ signal to call a QML slot

Sorry to say that's not even close to how it works...

 

Take a look at some of the samples or this,

 

http://developer.blackberry.com/cascades/documentation/dev/signals_slots/

 


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.
Developer
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: Trouble emitting C++ signal to call a QML slot

Thanks Zmey, that works.  I tried using the Connections element before, but did not know that it needed to be placed in attachedObjects.  Thanks again.