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

Posts: 30
Registered: ‎09-01-2013
My Device: Q5
My Carrier: Orange
Accepted Solution

App crashes when defining App

So I am working off this example; https://github.com/thurberdog/BlackBerryCascades/tree/master/pushCollector


I've written a function and added it to app.cpp;


void App::registerToServer(QString apiURL, QUrl params)
	QUrl serviceUrl = QUrl(apiURL);
	QByteArray postData;
	postData = params.encodedQuery();

    QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);


    // Connect to the reply finished signal.
    connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(httpFinished(QNetworkReply*)));

void App::httpFinished(QNetworkReply* reply)
	qDebug() << "httpFinished called";
   // qDebug() << reply->readAll();
    int code = -1;
    QString description;
    QString returnCode;

    returnCode = reply->readAll();
    qDebug() << "RC: " + returnCode;
    	showDialog(tr("Device Registration"), tr("Your device has been successfully registered!"));
    	changeConnectionText("Connection Status: Connected!");

    } else if (returnCode == "rc=1002"){
    	showDialog(tr("Device Registration"), tr("Unable to register your device. Please try again later. E1002"));
    	changeConnectionText("Connection Status: Error E1002");
    } else if (returnCode == "rc=1003"){
    	showDialog(tr("Device Registration"), tr("Your device has already been registered. Please login to your account online and remove you device. E1003"));
    	changeConnectionText("Connection Status: E1003");
    } else if (returnCode == "rc=1004"){
    	showDialog(tr("Device Unregistration"), tr("Your device has been unregistered."));
    	changeConnectionText("Connection Status: Not Connected");
    } else if (returnCode == "rc=1005"){
    	showDialog(tr("Device Unregistration"), tr("Unable to unregister from our servers. E1005"));
    	changeConnectionText("Connection Status: Unable to unregister. E1005");

    emit closeActivityDialog();


 Now in the Push.cpp file, when I try to do;


App m_app;

m_app.registerToServer(etc etc)

 My app crashes with the following;

terminated SIGSEGV code=1 fltno=11


Any help would be appreciated! I'm pretty new to this, so go easy Smiley Wink

Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: App crashes when defining App



the problem is that you have declared m_app of type App but it has no value and so when you try to invoke your function, you're getting a SIGSEGV. If you know Java, this is like a NullPointerException.


You need to either pass a pointer to your App object into Push.cpp or make it possible to obtain one from within Push.cpp. One possibility is to use the Singleton pattern. See the Statemanager.hpp / Statemanager.cpp class in NfcTool for an example. You then just call YourClass->getInstance() to obtain a pointer to the single instance of that class and can then call its functions/methods.




Hope this helps



Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Posts: 30
Registered: ‎09-01-2013
My Device: Q5
My Carrier: Orange

Re: App crashes when defining App

Ahh, super, thanks!