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
Contributor
ishar
Posts: 10
Registered: ‎06-23-2012
My Device: Blackberry 10 Dev Alpha

Signal with parameter from C++ to QML

Hi all,

I am trying to send a QString variable from C++ to QML using signals/slots system. I am using following code (simplified):

 

<header file>
signals:
   void billybird_sendMessage(QString message);
</header file>

<source file>
QmlDocument *qml = QmlDocument::create("asset:///login.qml").parent(this);
AbstractPane *root = qml->createRootObject<AbstractPane>();

connect(this, SIGNAL(billybird_sendMessage(QString)), root, SLOT(loginpage_onSendMessage(QString)));

emit billybird_sendMessage("some text");
</source file>

<qml>
import bb.cascades 1.0

Page {
    id: loginPage
    objectName: "loginPage"
    function loginpage_onSendMessage(message) {
        infoField.text = message
    }
    Container {
            Label {
                id: infoField
                preferredWidth: 710.0
            }
        }
    }
}
</qml> 

 When I remove Qstring from slot part of the connect function:

SLOT(loginpage_onSendMessage())

and QML function:

    function loginpage_onSendMessage() {
        infoField.text = qsTr("no params test")
    }

it works - but passing a parameter does not.

 

What I am doing wrong?

 

Many thanks in advance!

Please use plain text.
Contributor
ishar
Posts: 10
Registered: ‎06-23-2012
My Device: Blackberry 10 Dev Alpha

Re: Signal with parameter from C++ to QML

Changing the QString to QVariant fixed the issue, but I still don't really get the root cause of problem...

Please use plain text.