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
SumiSadiq
Posts: 148
Registered: ‎04-08-2013
My Device: Blackberry 10
Accepted Solution

Connecting signal in C++ with Slot in QML

In my app.cpp class

 

1)I have declared  a signal named 'activityStopSignal'

2)From this class I load a qml file

 

Here is my c++ class

#ifndef ApplicationUI_HPP_
#define ApplicationUI_HPP_
#include <QObject>
#include<bb/cascades/Application>
#include <bb/cascades/ListView>

#include <bb/data/SqlConnection>
#include <bb/data/DataSource>
#include <QtSql/QtSql>

using namespace bb::data;
using namespace bb::cascades;

namespace bb
	{
		namespace cascades
			{
				class Application;
				class SqlConnection;
				class ListView;
			}
	}

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

   signals :
      	void activityStopSignal(); ///here I have defined the signal

private slots:
   void replyFinished(QNetworkReply* netReply);

private:
    void Initialise();
    bb::data&colon;:SqlConnection* m_sqlConnection;
    bb::cascades::AbstractPane *rootLoginEng;
};


#endif /* ApplicationUI_HPP_ */

 

 

In that qml file

1)i have defined the slot for the signal 'activityStopSignal'

2)I gave the connection with the signal and slot

 

below is my qml file

 

import bb.cascades 1.0

Page {
    Container {
        layout: DockLayout {

        }

        Container {
            layout: DockLayout {

            }          
            ImageView {
                imageSource: "asset:///images/logo.png"
            }
        }
        ActivityIndicator {
            id: activity          
        }

    }

    onCreationCompleted: 
    {
        activity.start();        
        _myClass.activityStopSignal.connect(activityDone) //here i have given the connection to the signal

    }


    function activityDone() {
        activity.stop();
        _myClass.loadHomePage();
    }

}

Now my problem is:

When I try to call 'emit activityStopSignal' the app crashes.Where Iam wrong Plz help me out

 

 

 

 

 Below is the app.cpp file where Ian trying to emit the signal

 

// Default empty project template
#include "applicationui.hpp"
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/Page>

using namespace bb::cascades;
using namespace bb::system;
using namespace bb::data;


ApplicationUI::ApplicationUI(bb::cascades::Application *app)
: QObject(app)
{
      Initialise(); 
      QmlDocument *qml = QmlDocument::create("asset:///splashScreen.qml").parent(this);
      qml->setContextProperty("_myClass", this);
      AbstractPane *root = qml->createRootObject<AbstractPane>();
      app->setScene(root);

      postJsonRequests(); 
      emit activityStopSignal(); //here I emit the signal
}

 

Anyone plz help me :smileysad:

 

 

Please use plain text.
Developer
simon_hain
Posts: 16,190
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Connecting signal in C++ with Slot in QML

the signal connection looks ok, i would suggest that you remove the code in your function and use a simple console.log to see if it is called properly.

If you want to process the json request first before emitting the signal you should check your code, networking is async so your postJsonRequest will most likely return before the networking is finished.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
SumiSadiq
Posts: 148
Registered: ‎04-08-2013
My Device: Blackberry 10

Re: Connecting signal in C++ with Slot in QML

[ Edited ]

Thank u so much @simon,

  The problem is with the function LoadHomePage which Iam calling from the signal handler.As i already have loaded one QML page now I want to load another qml page.So I tried to kill the previously loaded Qml page to reduce memory problems.What I done is below

void ApplicationUI::loadHomePage()
	{
	QmlDocument *qmlLoginEng =    QmlDocument::create("asset:///homePage.qml").parent(this);
	qmlLoginEng->setContextProperty("_myClass", this);
	rootLoginEng = qmlLoginEng->createRootObject<AbstractPane>();
	rootLoginEng->setParent(this);

	
     Application::instance()->setScene(0); //I think this line will kill the older qml page.But this is the line where I got the crash
	
     Application::instance()->setScene(rootLoginEng);
	}

 What Is the correct way to kill one old page before loading a new one

Please use plain text.
Developer
simon_hain
Posts: 16,190
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Connecting signal in C++ with Slot in QML

I use the destroy() method, maybe a deleteLater on the qmlLoginEng will also work.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.