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
calicratis19
Posts: 163
Registered: ‎12-06-2012
My Device: Z10, Q10
My Carrier: BlackBerry
Accepted Solution

Can't setParent to a page after calling resetScene

 

Previously I set a Page as the scene. If I try to reset it and then set the scene with a TabbedPane then it works fine. But if I want to reset the scene and then want to set it's parent to null and delete it then I get exception while setting the parent to null or other object. Why its happening?

 

	AbstractPane *pane = this->app->scene();
	this->app->resetScene();
	if(pane != NULL)
	{
		pane->setParent(NULL);// exception here
		delete pane;
	}
	this->app->setScene(filteringPane);

 Thanks.

Please use plain text.
Developer
Zmey
Posts: 1,511
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Can't setParent to a page after calling resetScene

If the Page is owned by Application, I suspect that resetScene() deletes it contrary to what the docs say.

 

This seems logical, because docs for setScene state that the previous scene will be deleted if it's owned by Application. I don't see why resetScene() wouldn't work the same:

http://developer.blackberry.com/native/reference/cascades/bb__cascades__application.html#function-se...

 

So, it looks like that after a call to resetScene() the old pane no longer exists.

'pane' won't become NULL because it's just a local variable holding an address, resetScene() can't change it.

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
calicratis19
Posts: 163
Registered: ‎12-06-2012
My Device: Z10, Q10
My Carrier: BlackBerry

Re: Can't setParent to a page after calling resetScene

[ Edited ]

Oops I didn't see the setScene function. I saw the resetScene and there nothing about deleting was mentioned. So the page and all its underlying UIObjects will be deleted automatically after I call resetScene. Thanks.

Please use plain text.
Developer
Zmey
Posts: 1,511
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Can't setParent to a page after calling resetScene

[ Edited ]

Yes. I've created a simple test project to confirm that this is a documentation bug:

 

TestPage.h

#ifndef TESTPAGE_H
#define TESTPAGE_H

#include <QObject>
#include <bb/cascades/Page>

class TestPage : public bb::cascades::Page
{
	Q_OBJECT
public:
	explicit TestPage(Page *parent = 0);
	virtual ~TestPage();
	
signals:
	
public slots:
	
};

#endif // TESTPAGE_H

 TestPage.cpp

#include "TestPage.h"

TestPage::TestPage(Page *parent) :
	Page(parent)
{
	qDebug() << "TestPage created";
}

TestPage::~TestPage()
{
	qDebug() << "TestPage destroyed";
}

 CascadesTest.cpp:

 

#include "CascadesTest.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>

#include "TestPage.h"

CascadesTest::CascadesTest(bb::cascades::Application *app)
	: QObject(app)
{
	bb::cascades::QmlDocument *qml = bb::cascades::QmlDocument::create("asset:///main.qml").parent(this);
	bb::cascades::AbstractPane *root = qml->createRootObject<bb::cascades::AbstractPane>();

	TestPage *testPage = new TestPage;
	app->setScene(testPage);

	app->resetScene();

	app->setScene(root);
}

 Output:

TestPage created 
TestPage destroyed 

 

 UPD: resetScene() is not needed. I commented it out and setScene destroys the page as well.

 

 UPD2: if I comment out setScene() but leave resetScene() the page is also destroyed.

 

UPD3: Created a JIRA ticket. https://www.blackberry.com/jira/browse/BBTEN-1726


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