09-24-2012 12:43 AM
The User interface code is qml code and i want to write logic in CPP then how to get that controls values in cpp
09-24-2012 12:58 AM
Hi,
You can do with set object name in QML and find reference using findchield in cpp.
(You can do same thing many way but it's jus example)
Qml
age {
content: Container {
objectName: "myContainer"
Button {
text: "Button"
}
}
}CPP
Container *container = root->findChild<Container*>("myContainer");Also you can use Q_INVOKABLE Macro
Q_INVOKABLE QString getDevicePIN();
for call cpp logic method from qml .
for more detail please check this link
https://developer.blackberry.com/cascades/document
09-24-2012 01:30 AM
Hi ,
You can get the control reference from the qml file by using the findChild metod in cpp and you can set the values of a control by setter methods of that control.
For example:
main.qml
import bb.cascades 1.0
Page {
Label {
objectName: "objlabel"
text: "some text here"
}
}
app.cpp
App::App()
{
QmlDocument *qml = QmlDocument::create("main.qml");
AbstractPane *root = qml->createRootNode<AbstractPane>();
Label *lbl=root->findChild<Label *>("objlabel");
lbl->setText("text changed from cpp");
Application::setScene(root);
}
This is a simple example for accessing reference of controls in qml file using cpp.
If u want to set the property of a control existed in qml do like this
Page{
Property alias text : lbl.text
Label{
id:lbl
text:"some text"
}
}
app.cpp
root->setProperty("lbl","text changed");
By these two ways u can access and change the control values from cpp.
For more information just check the below link https://developer.blackberry.com/cascades/document
09-24-2012 01:41 AM
pls send me a simple example
09-24-2012 02:09 AM
if the screen has 15 controls than we have to call findchild 15 times no alternative for this na and the second we can set the value in text field then how to get value present in textfield
09-24-2012 02:36 AM
Hi,
You can get the reference of the control from qml file in cpp using findChild method and i don't know any other alternative is there or not. Second ,you can get the value from the text field usingtext() method for that control.Please see the documentation of a control u can get the methods ,signals and slots available for that particular control.
Regards,
Naresh Kodumuri.
09-25-2012 09:36 AM
Ok don't do this.
There is one alternative where you can have any number of controls in CPP. Just create them with in the App() or wherever you are setting the scene for the app.
For root node of app's visual scene, you need to have a reference to an object of any subclass of AbstractPane(Page, TabbedPane, NavigationPane etc).
You can have it like this.
Page *root = new Page;
Since a Page accepts a single control object as its content. So for several control objects you need to have a Container object that can have any no. of control objects within itself.
Container *container = new Container();
container->setLayout(
StackLayout::create().top(20.0f).direction(
LayoutDirection::TopToBottom));
Now create any no. of Label controls you want with container as its parent.
Label *label1 = new Label(container); Label *label2 = new Label(container);
...so on
To root node(Page control) set container as its content.
root->setContent(container);
and then set this page as scene to the application UI
Application::setScene(page);
This will avoid any interaction with qml files.