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
Trusted Contributor
itcraps
Posts: 238
Registered: ‎12-26-2010
My Device: BlackBerry Z10
Accepted Solution

Question about Cascades Development using C++ and QML

Hi all, I have been experimenting and create Cascades apps for more than a month.

 

I used c++ (where I am a c++ newbie too) all the time to build apps and ignore qml.

 

I am at the point where I need to create List in my app and it is using the MVC architecture that I am not familiar with.

 

So my question is:

 

Lets say, I have a Page, a Container which are coded in C++, can I create a List in qml and then "call" it and add it to my C++ container??

If the answer is yes, is there anyone kind enough to provide a little sample code on this??

 

Thank you

 

 

 

www.jackdevora.com
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Question about Cascades Development using C++ and QML

[ Edited ]

Your words are slightly confusing.

 

If you are asking to add a page to a listitem then no, not possible.

If you are asking to add a list created in QML and add it to your C++ container then yes.

 

If it's a static qml object the you can load the page in c++ code at compile time.

If you wish to dynamically add a QML ListView to a container at runtime then you would need to pass the object either through a Q_PROPERTY or a Q_INVOKABLE one.

 

An easier way is to set the objectName of your ListView and then passes that to a function in your C++ that then searches for it and adds it,

 

QML

 

ListView {
   id: lv
   objectName: "bob"   // Dynamically change if you wish

   //  ... ListView stuff
}

Button {
    text: "Click to add ListView"
    onClicked: {
        _app.addList(lv.objectName)
    }
}

 

C++ 

 

void addList(QString name) {
   ListView* lv = (ListView *)mPage->findChild(name);
   mContainer->add(lv);
}

 Not at my computer (i.e. coded from memory), so might not be exactly right but something like that. :smileyhappy:

 


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

Developer of stokLocker, Sympatico and Super Sentences.
Trusted Contributor
itcraps
Posts: 238
Registered: ‎12-26-2010
My Device: BlackBerry Z10

Re: Question about Cascades Development using C++ and QML

Thank you for the clear explanation.
www.jackdevora.com
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Question about Cascades Development using C++ and QML

You're welcome.

 

At the time I wrote this I gave you some code that would work but possibly not the best code for what you are trying to do as the code is circuitous to allow for dynamic adding of ListViews from QML to C++, a requirement I might have misinterpreted from your OP.

 

For instance if all you want to do is access a ListView in your QML from C++ then just giving it an objectName and hardcoding that name within the findChild line is all you would need.

 

If you do need to add dynamically allocated ListViews I would probably not bother with the QML at all and just add it directly in your container class all in C++. If you did want to do it via QML then I would suggest using ComponantDefintion or ControlDelegate.

 

I may be overthinking your problem. :smileyhappy:

 


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

Developer of stokLocker, Sympatico and Super Sentences.