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
Contributor
MichalKozminski
Posts: 36
Registered: ‎07-05-2012
My Device: 9900 & dev alpha

QML crashesh after sending QObject pointer

I get this code to get Board class

QObject* Class::getBoardById(int id){
qDebug() << "get organization:";
AbstractObjectBase* test = organizationsList->at(id);
qDebug() << " get as abstractobject";
QObject* sample = qobject_cast<QObject*>(test);
qDebug() << "sending as qobject";
return sample;
}

After I eveal this function from QML first time I get My Board in console: Board(0x860bc20) but if I eval it after couple of seconds I get:

Jan 23 17:30:19.144 com.example.twitter.testDev_ple_45fff82.33444034              default   9000  =======
Jan 23 17:30:19.146 com.example.twitter.testDev_ple_45fff82.33444034              default   9000  get organization: 
Jan 23 17:30:19.146 com.example.twitter.testDev_ple_45fff82.33444034              default   9000   get as abstractobject 
Jan 23 17:30:19.146 com.example.twitter.testDev_ple_45fff82.33444034              default   9000  sending as qobject 
Jan 23 17:30:19.146 com.example.twitter.testDev_ple_45fff82.33444034              default   9000  Organization(0x8646af0)
Jan 23 17:30:48.592 com.example.twitter.testDev_ple_45fff82.33444034              default   9000  =======
Jan 23 17:30:48.592 com.example.twitter.testDev_ple_45fff82.33444034              default   9000  get organization: 
Jan 23 17:30:48.593 com.example.twitter.testDev_ple_45fff82.33444034              default   9000   get as abstractobject 

 

and app froze and crashes. What could be the problem?

Developer
kylefowler
Posts: 526
Registered: ‎05-17-2009
My Device: 9900

Re: QML crashesh after sending QObject pointer

you should post the stack trace of when it crashes, run it in debug mode.

A few possibilities, youre returning a null pointer then trying to do something to it or the parent of the object is switching and the object is getting cleaned up.
Like all of my posts
Contributor
MichalKozminski
Posts: 36
Registered: ‎07-05-2012
My Device: 9900 & dev alpha

But if run this code without return and return to qml cle...

But if run this code without return and return to qml clean QObject everything works. There is problem between c++<->qml layer. I tried debug mode but I get only arm disassemble which I can't understood. 

New Contributor
jnetterf
Posts: 2
Registered: ‎03-04-2013
My Device: Z10 (STL100-1)

Re: But if run this code without return and return to qml cle...

[ Edited ]

There are a lot of reasons why this could be happening.

 

In my own app, Podcasts, I discovered that qml is quite finicky about ownsership. You should make sure that whatever you are sending to qml-land has a parent of NULL so that qml-land can take ownsership of it.

 

(Edit: sorry for reviving this old thread. Hope this helps someone nonetheless.)