Blackberry 10 개발을 처음 사용했습니다. 저는 간단한 BB 10 계단식 프로젝트를 만들었습니다. C++ 함수를 통해 레이블의 텍스트를 변경하려고합니다.qml에서 C++ 함수를 호출하고 lable 텍스트를 변경하는 방법
main.qml
import bb.cascades 1.0
Page {
content: Container {
id: containerID
Button {
id: button1
objectName: "button"
text: "text"
onClicked: {
btnClicked("New Label Text");
}
}
Label {
id: label1
objectName: "label1"
text: "Old Label Text"
}
}
}
지금 어떤 파일에 내가 선언했습니다 어느 파일에 난 기능 btnClicked (QString) 함수를 정의했습니다. HelloBB.hpp
// Default empty project template
#ifndef HelloBB_HPP_
#define HelloBB_HPP_
#include <QObject>
namespace bb { namespace cascades { class Application; }}
class HelloBB : public QObject
{
Q_OBJECT
public:
HelloBB(bb::cascades::Application *app);
virtual ~HelloBB() {}
};
#endif
HelloBB.cpp
// Default empty project template
#include "HelloBB.hpp"
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
using namespace bb::cascades;
HelloBB::HelloBB(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("app", this);
// create root object for the UI
AbstractPane *root = qml->createRootObject<AbstractPane>();
// set created root object as a scene
app->setScene(root);
}
는 지금은 사용자 지정된 텍스트에 올드 레이블 텍스트에서 레이블 텍스트를 변경하고 싶습니다. qml에서 C++ 함수를 호출합니다. 이 함수를 정의 할 위치와 QML에서이 C++ 함수를 연결하는 방법을 알지 못합니다.
감사합니다.
당신은 C++ 여기 QML 통합 문서를 찾을 수 있습니다