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
Posts: 29
Registered: ‎03-03-2013
My Device: Z10, Q10, Bold 9900, Bold 9700
My Carrier: Rogers

Loading a page in C++, returning it to a navigation pane in QML

I'm attempting to push a page in QML that is returned from a C++ method, however it doesn't seem to be working properly.

 

When an event is triggered in a list view which resides in a navigation pane, I do the following:

                        onTriggered: {
                            var itemData = myDataModel.data(indexPath);
                            var newPage = pageDisplay.generatePage(itemData.path);
                            navId.push(newPage);
                        }

 

Which then calls into my generatePage method in my exposed pageDisplay class.  This method looks something like this: 

Page* PageDisplay::generatePage(QString path) {
	QmlDocument* newDoc = QmlDocument::create(QUrl("asset:///myPage.qml"));
	Page* newPage = newDoc->createRootObject<Page>();

// Load some text into page labels here

return newPage
}

 

For some reason this doesn't have the desired effect.  I modified the end of my generatePage method to the following and it worked, however it isn't a usable solution for my project as it will be used for multiple navigation panes:

Page* PageDisplay::generatePage(QString path) {
	QmlDocument* newDoc = QmlDocument::create(QUrl("asset:///myPage.qml"));
	Page* newPage = newDoc->createRootObject<Page>();

// Load some text into page labels here

	NavigationPane* navPane =
			Application::instance()->findChild<NavigationPane*>(
					"navigationPaneObjectName");
	navPane->push(newPage);
        return NULL;
}

 

I have a feeling I'm missing something simple here, but I just can't seem to figure it out.  Thanks in advance!

 

 

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Loading a page in C++, returning it to a navigation pane in QML

i would try to create a new Page object without any qmldocument stuff around it.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 29
Registered: ‎03-03-2013
My Device: Z10, Q10, Bold 9900, Bold 9700
My Carrier: Rogers

Re: Loading a page in C++, returning it to a navigation pane in QML

I have also tried that, with no luck.  I just returned Page::create() at the end of my method to see if I could push a blank page and still had the same problem.

Developer
Posts: 29
Registered: ‎03-03-2013
My Device: Z10, Q10, Bold 9900, Bold 9700
My Carrier: Rogers

Re: Loading a page in C++, returning it to a navigation pane in QML

I've kept trying to get this working, but no luck. Does anyone else have any idea what could be wrong?
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Loading a page in C++, returning it to a navigation pane in QML

Is the log not giving you any error messages?

 

I do something similer but don't have the time to adapt it to what you've put today.

My guess would be the QML is not recognising the returned pointer as a Page or something similer.

 

If you haven't fixed it by tomorrow I'll have a go at adapting my code.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 196
Registered: ‎03-04-2013
My Device: BB Z10
My Carrier: Rogers

Re: Loading a page in C++, returning it to a navigation pane in QML

[ Edited ]

Well, you have certainly narrowed down the problem I would say.

 

Is the Page* actually being returned to your QML file?  If yes, is navId actually attempting to push the new Page?

 

I would assume the Page* is actually being returned, so perhaps it's the navId that's not working.  Try something else in onTriggered with the navId object.

 

--Edit--

Hehe @BBSJdev

 

--------

For example, got this clip from the Nagivation Pane API description example:

                onTriggered: {
                    var page = pageDefinition.createObject();
                    navigationPane.push(page);
                }
 
                attachedObjects: ComponentDefinition {
                    id: pageDefinition;
                    source: "secondpage.qml"
                }

 

If it's not recognizing it as a Page*, maybe casting it would work?  Dunno...

Developer
Posts: 196
Registered: ‎03-04-2013
My Device: BB Z10
My Carrier: Rogers

Re: Loading a page in C++, returning it to a navigation pane in QML

[ Edited ]

Well, just wrote something to test this out and it's working for me..  Following are the files with the relevant areas.

 

.hpp

class Testme : public QObject
{
    Q_OBJECT
public:
    Testme(bb::cascades::Application *app);
    virtual ~Testme() {}
    Q_INVOKABLE bb::cascades::Page *generatePage();
};

 

.cpp

Page* Testme::generatePage() {
	QmlDocument *qml_new = QmlDocument::create("asset:///main2.qml");
	Page* newPage = qml_new->createRootObject<Page>();

	Container* contentContainer = new Container();
	contentContainer->setLayout(StackLayout::create());

	Label* contentLabel = new Label();
	contentLabel->setText("Second Page");

	contentContainer->add(contentLabel);
	newPage->setContent(contentContainer);

	return newPage;
}

 

main.cpp

    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(&app);
    qml->setContextProperty("_Testme", new Testme(&app));

    // create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    // set created root object as a scene
    app.setScene(root);

 

main.qml

       actions: [
            ActionItem {
                title: "Next page"
                ActionBar.placement: ActionBarPlacement.OnBar
                onTriggered: {
                    var page = _Testme.generatePage();
                    navigationPane.push(page);
                }
            }
        ]

 

Developer
Posts: 29
Registered: ‎03-03-2013
My Device: Z10, Q10, Bold 9900, Bold 9700
My Carrier: Rogers

Re: Loading a page in C++, returning it to a navigation pane in QML

Thanks for your reply jalue!  I don't have access to my code this weekend as I'm away from my development computer, but I'll take another look on Monday when I get back.  I feel like my code is very similar to that, but maybe I'm missing something simple.  I'll give that example a shot and come back with my results!