in BlackBerry 10 we can integrate QML TO C++ CODE and C++ CODE to QML. create a new project with name HelloPratice2 we can see it with following code snipet. just copy these code snipets to mai.qml and correspondin CPP file.
1)copy the below code to main.qml
import bb.cascades 1.0
Page {
property alias labelText: label.text
Container {
Label {
text: "User name: " + propertyMap.name
}
Label {
text: "Phone number: " + propertyMap.phone
}
Label {
id: label
text: "Label"
}
Button {
objectName: "button"
text: "Button"
}
}
}
1)copy the below code to main.qml
import bb.cascades 1.0
Page {
property alias labelText: label.text
Container {
Label {
text: "User name: " + propertyMap.name
}
Label {
text: "Phone number: " + propertyMap.phone
}
Label {
id: label
text: "Label"
}
Button {
objectName: "button"
text: "Button"
}
}
}
2) HelloPractice2.cpp file should have following code :
// Default empty project template
#include "HelloPractice2.hpp"
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
using namespace bb::cascades;
HelloPractice2::HelloPractice2(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);
// create root object for the UI
AbstractPane *root = qml->createRootObject<AbstractPane>();
// set created root object as a scene
QDeclarativePropertyMap* propertyMap = new QDeclarativePropertyMap;
propertyMap->insert("name", QVariant(QString("Wes Barichak")));
propertyMap->insert("phone", QVariant(QString("519-555-0199")));
qml->setContextProperty("propertyMap", propertyMap);
QObject *newButton = root->findChild<QObject*>("button");
if (newButton)
newButton->setProperty("text", "New button text");
app->setScene(root);
}
No comments:
Post a Comment