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 Developer
silajim
Posts: 23
Registered: ‎10-14-2013
My Device: Z10
My Carrier: Cosmote

Cannot define extra object on ApplicationUI.hpp

Hello people, happy hollydays for the ones that actualy have! :smileyvery-happy:

 

I am having an unexpicable problem for me, i have a problem when i try to define/declare a new object of a class in the ApplicationUI.hpp, the program compiles correctly but when it's time to run crashes at open, with this error: SIGSEGV code=1 fltno=11.

 

part of ApplicationUi.hpp:

 

private:
    Profile* _profile;
    Calendar* _calendar;
    Calendar* calendar() const;
    Notes* _notes;
    Notes* notes() const;
    Profile* profile() const;
//**************** Here **********//
    Sts *sts;
//*******************************//
    RegistrationHandler* registrationHandler;
    QString m_uuid;
    bb::platform::bbm::Context* m_context;
    bb::platform::bbm::UserProfile *m_userProfile;
    bb::platform::bbm::MessageService *m_messageService;
    Q_SLOT void positionUpdated (const QGeoPositionInfo &update);
    QTranslator* myTranslator;
    bb::cascades::LocaleHandler* myLocaleHandler;

 The Sts.h:

 

#ifndef STS_H_
#define STS_H_
#include <QtCore/QObject>
#include <QObject>
class Sts: public QObject
{
  Q_OBJECT

public:
	Sts(QObject *parent=0);
	virtual ~Sts();
};

#endif /* STS_H_ */

 And the Sts.cpp:

#include "Sts.h"

#include <QtCore/QObject>
#include <QObject>
Sts::Sts(QObject *parent): QObject(parent) {
	// TODO Auto-generated constructor stub

}

Sts::~Sts() {
	// TODO Auto-generated destructor stub
}

 But the problem doeas not accour  only with this class, it's allso happens if i declare another variable for hold another object, it doeas not matter the type, if it will be, Profile, Notes. or whatever.

 

The instruction that fires the error, is this one:

 

qml->setContextProperty("_app",this);

 

 

and this is how qml is declared: 

 

    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

 

Any help please? Thank you.

 

 

Please use plain text.
Developer
greenmr
Posts: 882
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Cannot define extra object on ApplicationUI.hpp

SIGSEGV is almost always caused by an attempt to call a class method on an object that doesn't exist, that is to say, the object pointer variable is null, or it points to an address that doesn't contain the object you expect, either because it was never instatiated or it did but the object was deleted.

 

I would investigate the possibility that qml does not actually contain a valid pointer to a QmlDocument when you try to call setContextProperty().



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.
Please use plain text.
New Developer
silajim
Posts: 23
Registered: ‎10-14-2013
My Device: Z10
My Carrier: Cosmote

Re: Cannot define extra object on ApplicationUI.hpp

Thank you for your response, but if I delete the Sts *sts from the ApplicationUI.hpp the program works correctly. The sts variable is never used in this example
Please use plain text.
Developer
greenmr
Posts: 882
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Cannot define extra object on ApplicationUI.hpp

Ok, in looking at your code again I'm curious why you have two headers specified for QObject in both Sts.h and Sts.cpp? Only one should be necessary, and that may be causing problems. I would remove the <QtCore/QObject> one.

 

Also, the QObject header specifications in Sts.cpp are redundant since they will have already been included due to the inclusion of Sts.h.



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.
Please use plain text.
New Developer
silajim
Posts: 23
Registered: ‎10-14-2013
My Device: Z10
My Carrier: Cosmote

Re: Cannot define extra object on ApplicationUI.hpp

I've tried also without the QObject header, but it's still the same problem...
Please use plain text.
Developer
greenmr
Posts: 882
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Cannot define extra object on ApplicationUI.hpp

Ok, so just to be sure we are on the same page, Sts.h should look like this:

 

#ifndef STS_H_
#define STS_H_
#include <QObject>
class Sts: public QObject
{
  Q_OBJECT

public:
	Sts(QObject *parent=0);
	virtual ~Sts();
};

#endif /* STS_H_ */

... and Sts.cpp like this:

 

#include "Sts.h"

Sts::Sts(QObject *parent): QObject(parent) {
	// TODO Auto-generated constructor stub

}

Sts::~Sts() {
	// TODO Auto-generated destructor stub
}

Is this what you tried?


silajim wrote:
I've tried also without the QObject header, but it's still the same problem...





Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.
Please use plain text.
New Developer
silajim
Posts: 23
Registered: ‎10-14-2013
My Device: Z10
My Carrier: Cosmote

Re: Cannot define extra object on ApplicationUI.hpp

#ifndef STS_H_
#define STS_H_
#include <QtCore/QObject>
class Sts: public QObject
{
  Q_OBJECT

public:
	Sts(QObject *parent=0);
	virtual ~Sts();
};

#endif /* STS_H_ */

 No QObject, but <QtCore/QObject>

Please use plain text.
Developer
greenmr
Posts: 882
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Cannot define extra object on ApplicationUI.hpp

I just reread your original post and I realized that you are saying that adding ANY new class members in the header causes a SIGSEGV, so we are probably wasting our time looking for the cause is Sts. I have to go back to my original suggestion, that the qml variable does not hold a valid pointer to a QmlDocument object when you call create(). Something in your code is probably trashing memory that doesn't belong to it. Unfortunately this can be very tricky to locate. Somewhere in your app you are probably writing to the target of an invalid pointer. Although this doesn't cause an immediate crash, later on when the app tries to use the object contained in the damaged memory location it generates the fault you are seeing.

 

This memory corruption must be happening either in main() or in the ApplicationUi constructor. Can you post the code in ApplicationUi::ApplicationUi()? Have you added anything to main().



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.
Please use plain text.
Developer
greenmr
Posts: 882
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Cannot define extra object on ApplicationUI.hpp

I believe both versions resolve to the same qobject.h file, but just so you know, you don't need the QtCore/ part, just <QObject> is sufficient.


silajim wrote:
#ifndef STS_H_
#define STS_H_
#include <QtCore/QObject>
class Sts: public QObject
{
  Q_OBJECT

public:
	Sts(QObject *parent=0);
	virtual ~Sts();
};

#endif /* STS_H_ */

 No QObject, but <QtCore/QObject>






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.
Please use plain text.
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Cannot define extra object on ApplicationUI.hpp

Try cleaning & rebuilding the project, this helps sometimes with strange crashes such as this one.

Andrey Fidrya, @zmeyc on twitter
Please use plain text.