Skip to content

Instantly share code, notes, and snippets.

@mbroadst
Created January 21, 2013 22:04
Show Gist options
  • Save mbroadst/4589919 to your computer and use it in GitHub Desktop.
Save mbroadst/4589919 to your computer and use it in GitHub Desktop.
// 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