Created
January 21, 2013 22:04
-
-
Save mbroadst/4589919 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TEST OBJECT CLASS | |
class TestObject : public QObject | |
{ | |
Q_OBJECT | |
Q_PROPERTY(QString testText READ testText WRITE setTestText) | |
public: | |
TestObject(QObject *parent = 0) | |
: m_testText("testing") {} | |
~TestObject() {} | |
QString testText() const { return m_testText; } | |
void setTestText(const QString &text) { m_testText = text; } | |
private: | |
QString m_testText; | |
} | |
// TEST.QML FILE | |
Rectangle { | |
// bindings | |
Binding { target: testobject; property: "testText"; value: field.text } | |
TextField { | |
id: field | |
} | |
} | |
// MAIN CPP | |
int main(int argc, char ** argv) | |
{ | |
QApplication app(argc, argv); | |
TestObject testObject; | |
QDeclarativeView view; | |
view.rootContext()->setContextProperty("testobject", &testObject); | |
QDeclarativeComponent component(view.engine(), QUrl::fromLocalFile("Test.qml")); | |
QObject *testInstance = component.create(); | |
view.show(); | |
return app.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment