我正在开发一个QML应用程序(黑莓10),并且有一个像这样的QML文件:
import bb.cascades 1.0
Page {
content: Container {
id: containerID
Button {
id: button1
text: "text"
onClicked: {
}
}
Label {
id: label1
text: "text"
}
}
}
现在我想在我的C++代码中访问,所以我有以下代码:
#include "app.hpp"
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
using namespace bb::cascades;
App::App()
{
QmlDocument *qml = QmlDocument::create("main.qml");
//-- setContextProperty expose C++ object in QML as an variable
//-- uncomment next line to introduce 'this' object to QML name space as an 'app' variable
//qml->setContextProperty("app", this);
AbstractPane *root = qml->createRootNode<AbstractPane>();
QObject *labelTest = root->findChild<QObject*>("label1");
if (labelTest)
labelTest->setProperty("text", "yes!!");
Application::setScene(root);
}
现在我运行了应用程序,但标签的文本没有改变。
出了什么问题?