1. DisturbedRocks31's Avatar
    I have never developed an app before and this is my first time, I've decided to go with BB10 Native cascades.

    Anyways, I'm trying to call a C++ function from the main.QML file when a button is pressed. But it's not working!

    I'm not sure what the problem is, I can get the button to do random stuff like show w.e. is in the input field but it doesn't call the C++ function.... It's also showing a warning: "Unknown Symbol 'HelloWorldBB10'" but I have no idea how to fix it. I thought adding the
    qml->setContextProperty("HelloWorldBB10", this);
    would fix that but it doesn't.

    Anyone know what I'm not doing?

    DropDown {
                id: direction
                objectName: "direction"
                title : "Converting to ..."
                enabled : true
                topMargin: 50.0
                onSelectedIndexChanged : {
                    console.log("SelectedIndex was changed to " + selectedIndex);
                // text + description
                horizontalAlignment: HorizontalAlignment.Center
                Option {
                     text : "Numbers"
                     description : "English To NUmbers"
                     value : "r"
                     selected : true
                 Option {
                     text : "English"
                     description : "Numbers To English"
                     value : "e"
     TextArea {
                id: inputText
                objectName: "inputText"
                hintText: "Enter or Paste Your Input Here!"
                inputMode: TextAreaInputMode.Default
                editable: true
                focusPolicy: FocusPolicy.Default
            Button {
                id: convertButton
                objectName: "convertButton"
                text: "Convert"
                onClicked: {
                    output.text = HelloWorldBB10.convert(inputText.text, direction.selectedValue);
            Label {
                id: output
                objectName: "output"
                text: ""
    Then, my HelloWorldBB10.hpp file is:
    // Default empty project template
    #ifndef HelloWorldBB10_HPP_
    #define HelloWorldBB10_HPP_
    #include <QtCore/QObject>
    #include <QtCore/QMetaType>
    #include <bb/cascades/Event>
    #include <bb/cascades/UiObject>
    #include <bb/cascades/Control>
    #include <QObject>
    #include <string.h>
    namespace bb { namespace cascades { class Application; }}
     * @brief Application pane object
     *Use this object to create and init app UI, to create context objects, to register the new meta types etc.
    class HelloWorldBB10 : public QObject
        HelloWorldBB10(bb::cascades::Application *app);
        Q_INVOKABLE std::string convert(std::string input, char direction);
        virtual ~HelloWorldBB10() {}
    #endif /* HelloWorldBB10_HPP_ */
    and finally my HelloWorldBB10.cpp is:

    HelloWorldBB10::HelloWorldBB10(bb::cascades::Application *app)
    : QObject(app)
        // create scene document from main.qml asset
        // set parent to created document to ensure it exists for the whole application lifetime
        QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
        qml->setContextProperty("HelloWorldBB10", this);
        // create root object for the UI
        AbstractPane *root = qml->createRootObject<AbstractPane>();
        // set created root object as a scene
    std::string HelloWorldBB10::convert(std::string input, char direction)
    //function left out...
    return input;
    Last edited by JameB; 12-25-12 at 01:07 AM.
    12-24-12 10:43 PM
  2. travisredpath's Avatar
    I think the problem is that you're trying to use std::string in the Qt world, change them to QString and see if that fixes it. I think the char should work because it's just a short integer but if you still have problems there is also a QChar but you probably want an int.
    DisturbedRocks31 likes this.
    12-25-12 12:17 AM
  3. DisturbedRocks31's Avatar
    Thanks A Lot! That was spot on.
    12-25-12 01:06 AM

Similar Threads

  1. Call Blocker now available from Mobihand
    By EpicDraws in forum BlackBerry OS Apps
    Replies: 28
    Last Post: 05-13-09, 07:42 AM
  2. Replies: 5
    Last Post: 05-08-09, 07:57 AM
  3. "Search" Functionality from Calendar
    By brucem76 in forum General BlackBerry Discussion
    Replies: 2
    Last Post: 04-08-09, 06:10 AM
  4. How do I access call logs and textmessage from my computer?
    By tomrey in forum BlackBerry Curve 83xx
    Replies: 16
    Last Post: 04-06-09, 09:17 AM
  5. Called my Favorite rep from Verizon Wireless in DC today..
    By ClassaN0va in forum BlackBerry Storm
    Replies: 0
    Last Post: 11-21-08, 10:12 AM