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 Code:
qml->setContextProperty("HelloWorldBB10", this); would fix that but it doesn't.
Anyone know what I'm not doing? 
Relevant Code:
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:
Code:
// 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
{
Q_OBJECT
public:
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:
Code:
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
app->setScene(root);
}
std::string HelloWorldBB10::convert(std::string input, char direction)
{
//function left out...
return input;
}