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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip
Accepted Solution

How to connect slot to cascades Button

I'm new to Cascades and QML, and yesterday I tried to port native QtWidget app to Cascades, but it doesn't work. The problem is, I add few buttons to container in main QML file and coded my custom slot function that should be executed when user click some button. But I don't know how to connect clicked() signal to my custom slot function.


When I use  

connect(closeButton,SIGNAL(Button::clicked()),this,SLOT(on_closeButton_clicked())); or connect(exitButton,SIGNAL(clicked()),this,SLOT(on_exitButton_clicked())); I get "Can't connect SIGNAL(null) to SLOT(on_closeButton_clicked())" errors on all buttons.


Here is my code in app.cpp


    QmlDocument *qml = QmlDocument::create("main.qml");
    qml->setContextProperty("cs", this);

    AbstractPane *root = qml->createRootNode<AbstractPane>();
    textHolder = root->findChild<TextArea*>("textHolder");
    openButton = root->findChild<Button*>("openButton");
    saveButton = root->findChild<Button*>("saveButton");
    saveAsButton = root->findChild<Button*>("saveAsButton");
    closeButton = root->findChild<Button*>("closeButton");
    exitButton = root->findChild<Button*>("exitButton");

//one slot function

void App::on_closeButton_clicked()
//if(file.open(QIODevice::ReadOnly | QIODevice::Text)){


And qml

import bb.cascades 1.0

Page {
    id: mainPage
    Container {
    id: main
    Container {
    id: buttonHolder
    scrollMode: ScrollMode.None
            layout: StackLayout {
                layoutDirection: LayoutDirection.LeftToRight
                leftPadding: 5.0
                rightPadding: 5.0
                topPadding: 5.0
                bottomPadding: 5.0
            touchPropagationMode: TouchPropagationMode.None
            objectName: "buttonHolder"
            Button {
                id: openButton
                text: "Open"
            Button {
                id: closeButton
                text: "Close"
                onClicked: {
            Button {
                id: saveButton
                text: "Save"
                onClicked: {
            Button {
                id: saveAsButton
                text: "Save As"
                onClicked: {
            Button {
                id: exitButton
                text: "Exit"
        Container {
            id: textHolderArea
            layout: AbsoluteLayout {
            topMargin: 5.0
            leftMargin: 1.0
            rightMargin: 1.0
            bottomMargin: 2.0
            TextArea {
                id: textHolder
                textStyle.fontStyleHint: FontStyleHint.Default
                layoutProperties: AbsoluteLayoutProperties {
                leftMargin: 5.0
                rightMargin: 5.0
                preferredHeight: 645.0
                textStyle.justification: TextJustification.Enabled
                objectName: "textHolder"
                text: ""



And I have no idea how to call my C++ slot from app.cpp in my main QML file



Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: How to connect slot to cascades Button

Your buttons will need an objectName defined to be visible to C++, the id is only visible from within the QML.

Goodbye everybody!