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
hendrik
Posts: 63
Registered: ‎09-10-2009
My Device: Z10, Bold 9700
My Carrier: O2 Germany
Accepted Solution

How to pass a Container created in QML to a C++ method

I have defined a Container in QML:

attachedObjects: [
        ComponentDefinition {
            id: entryContainerDefinition
            Container {
                ...
            }
        }
]

 

Then I create the Container in QML and call a C++ utility method, which should dynamically add context menu actions based on some other parameters:

var entryContainer = entryContainerDefinition.createObject(this);
dsUtil.addActionsToContainer(entryContainer, [other params...]);

 

But when I execute it, I only get the following error:

"BoxContainer.qml:45: Error: Unknown method parameter type: Container*"

 

Is it not possible to create a Container in QML and then pass it to C++ in order to modify it dynamically?

----

My Twitter: @hendrik_dev
Developer
hendrik
Posts: 63
Registered: ‎09-10-2009
My Device: Z10, Bold 9700
My Carrier: O2 Germany

Re: How to pass a Container created in QML to a C++ method

I found a working solution myself. I am now passing QObject* instead of Container*:

void dsUtil::addActionsToContainer(QObject* containerObject, [...]) {
    // Cast QObject to Button
    Container* container = dynamic_cast<Container *>(containerObject);

    if (container) {
        ...
    }
}

 

----

My Twitter: @hendrik_dev
Developer
jasoncheung
Posts: 67
Registered: ‎09-01-2012
My Device: Dev Alpha

Re: How to pass a Container created in QML to a C++ method

I haven't done it with a container before but for other objects, I've given them an ObjectName: property and then I pass that back to my C++.