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
xhotkey
Posts: 48
Registered: ‎09-19-2012
My Device: 9700

How to load a new page from a qml file in c++?

How to load a new page from a qml file in c++?
I invoked a c++ function in QML to load a new qml page, but the UI just froze:
QmlDocument *qml = QmlDocument::create("asset:///analyser.qml");
 
// create root object for the UI
root = qml->createRootObject<AbstractPane>();
// set created root object as a scene
mApp->setScene(0);
mApp->setScene(root);
 
rotation = new RotationSensor(mApp);
qml->setContextProperty("rotation", rotation);
 
Or, if I load a new QML file from QML( not from c++), how to setContextProperty?
Please use plain text.
Developer
bobdodd
Posts: 116
Registered: ‎10-31-2012
My Device: BB10 Dev Alpha B

Re: How to load a new page from a qml file in c++?

Some C++ fragments that might help you (they don't worry about orientation tho).

 

	m_navigationPane = new NavigationPane;
	
	QmlDocument *qml = QmlDocument::create("asset:///main.qml");
	Page *p = qml->createRootObject<Page>();
	m_navigationPane->push(p);
	app->setScene(m_navigationPane);

        . . . . 

	// Create root container for results page
	Container *contentContainer = new Container();
	contentContainer->setLayout(StackLayout::create());
	contentContainer->setTopPadding(20.0f);
	contentContainer->setBackground(Color::White);

	// Create the scrollview for the results
	ScrollView * sv = new ScrollView();
	sv->scrollViewProperties()->setScrollMode(ScrollMode::Vertical);
	contentContainer->add(sv);

        . . . .

	// Push new results page to the screen
	Page *page = new Page();

	page->setContent(contentContainer);
	m_navigationPane->push(page);

 

 

Please use plain text.
Developer
bobdodd
Posts: 116
Registered: ‎10-31-2012
My Device: BB10 Dev Alpha B

Re: How to load a new page from a qml file in c++?

That's all from the C++ tho. If you wanted an event in main.qml to push the page, you would make the code that creates and pushes the page a Q_INVOKABLE method in your app (I think) so that it can be called from the Javascript in main.qml

Please use plain text.