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
SumiGhosh
Posts: 435
Registered: ‎09-20-2011
My Device: Z10 LE, Playbook, DevAlpha C, 9900, 9380

cpp created Container not adding to the qml container

Hi all,

 

In my qml i have a container, and i trying to insert a conainer in cpp class to the one created in qml. But the container is not adding.

Container {
            id:detailpage_middle_container
            objectName: "detailpage_middle_container"
            layout: DockLayout {}
            Container{
                layout: StackLayout {
                    orientation: LayoutOrientation.TopToBottom
                }
                Container {
                    id:database_search_top_container
                    leftPadding: 20.0
                    rightPadding: 20.0
                    preferredHeight: 110.0
                    preferredWidth: displayInfo.pixelSize.width
                    background: recent_container_bg.imagePaint
                    verticalAlignment: VerticalAlignment.Fill
                    horizontalAlignment: HorizontalAlignment.Fill
                    layout: StackLayout {
                        orientation: LayoutOrientation.LeftToRight
                    }
                    Label {
                        id:recent_label_name
                        preferredWidth: displayInfo.pixelSize.width/2
                        preferredHeight: 110.0
                        verticalAlignment: VerticalAlignment.Center
                        text: ""
                        textStyle.color: Color.White
                        textStyle.fontSize: FontSize.Large
                    }
                    CustomLabel {
                    	
                    }
                }
                CustomView {
                    id: cview
                    objectName: "cviewObj"
                    preferredWidth: displayInfo.pixelSize.width
                    preferredHeight: displayInfo.pixelSize.height==720?400:930 
                }
            }
            Container {
                id:asd
                objectName: "container_outer"
                verticalAlignment: VerticalAlignment.Bottom
                preferredWidth: displayInfo.pixelSize.width
                preferredHeight: 100
                
                //visible: false
                /*DetailContainer{
                    
                    //id:detail_container_custom
                    //objectName: "detail_container_custom"
                }*/  
            }           
                   
        }

 I am adding a cpp container to the container having object name "container_outer"

Please use plain text.
Developer
pyth
Posts: 508
Registered: ‎01-19-2011
My Device: My Trusty Red Plane

Re: cpp created Container not adding to the qml container

how are you adding the container? Is DetailContainer a cpp class? In that case you have to register your class to the qml of your main application, and your class needs to be derived from CustomControl

 

another possibiliy would just be to create a helper class, which injects any kind of cpp container into any qml container

-----------------------------------------------------------------------
I'm a bird from outer space. But I'm not flappy o.o
Please use plain text.
Developer
pyth
Posts: 508
Registered: ‎01-19-2011
My Device: My Trusty Red Plane

Re: cpp created Container not adding to the qml container

see https://developer.blackberry.com/native/documentation/cascades/dev/integrating_cpp_qml/

Chapter Using C++ classes in QML
and
Chapter Injecting C++ objects into QML
-----------------------------------------------------------------------
I'm a bird from outer space. But I'm not flappy o.o
Please use plain text.
Developer
SumiGhosh
Posts: 435
Registered: ‎09-20-2011
My Device: Z10 LE, Playbook, DevAlpha C, 9900, 9380

Re: cpp created Container not adding to the qml container

I am Posting full code.

 

DetailContainer.cpp

DetailContainer::DetailContainer() {	
	QmlDocument *qml = QmlDocument::create("asset:///DetailContainer.qml");
	rootContainer = qml->createRootObject<Container>();
}

Container * DetailContainer::sendRootContainer(){
	return rootContainer;
}

DetailContainer::~DetailContainer() {
	// TODO Auto-generated destructor stub
}

 And in my DetailPage.cpp

detailContainer = detailPage->findChild<Container*>("container_outer");
detailContainerObj = new DetailContainer();
	if(detailContainerObj->sendRootContainer()){
		detailContainer->add(detailContainerObj->sendRootContainer());
	}

 

Please use plain text.
Developer
pyth
Posts: 508
Registered: ‎01-19-2011
My Device: My Trusty Red Plane

Re: cpp created Container not adding to the qml container

your code looks ok. Try using qDebug() to see if detailContainer, detailPage, detailContainerObj and its rootContainer really exist
-----------------------------------------------------------------------
I'm a bird from outer space. But I'm not flappy o.o
Please use plain text.
Developer
SumiGhosh
Posts: 435
Registered: ‎09-20-2011
My Device: Z10 LE, Playbook, DevAlpha C, 9900, 9380

Re: cpp created Container not adding to the qml container

i have checked that already. It is existing.
Please use plain text.