伙计们,我正在开发BlackBerry 10的基本应用程序,我想得到的文本是在TextField (在cpp)。我正在尝试寻找方法,但没有得到正确的一个.So谁能告诉我如何从cpp (不是qml)中获取TextField的值?
发布于 2013-08-28 21:14:39
你需要做的第一件事就是把你的QML TextField暴露给C++。这是通过对象名称属性ala完成的:
TextField {
objectName: "myTextField"
...
}
接下来,从你的C++中找到这个孩子:
QmlDocument *qml = QmlDocument::create("asset:///my.qml");
Container *root = qml->createRootObject<bb::cascades::Container>(); //or whatever the root control is
TextField *textField = root->findChild<TextField*>("myTextField");
从那时起,只需使用textField->text()。
发布于 2013-08-28 16:40:51
我们在这个问题中有三个部分
首先在Qml中打开文本区和底部,然后单击send text area to function in c++
TextField {
id: n2
}
Button {
id: button
text: "send text"
onClicked: {
app.sendtext(n2.text)
}
第二部分是ApplicationUI中的c++函数,用于接收此文本
QString ApplicationUI::sendtext(QString txtarea)
{
QString text = txtarea;
return text;
}
您的ApplicationUI.h中的第三个也是最后一个部分必须使此函数可调用,才能在Qml中访问它
所以你需要这行代码
Q_INVOKABLE QString sendtext(QString txtarea);
https://stackoverflow.com/questions/18457776
复制相似问题