diff options
Diffstat (limited to 'examples/declarative/extending/adding')
-rw-r--r-- | examples/declarative/extending/adding/adding.pro | 11 | ||||
-rw-r--r-- | examples/declarative/extending/adding/adding.qrc | 5 | ||||
-rw-r--r-- | examples/declarative/extending/adding/example.qml | 8 | ||||
-rw-r--r-- | examples/declarative/extending/adding/main.cpp | 22 | ||||
-rw-r--r-- | examples/declarative/extending/adding/person.cpp | 30 | ||||
-rw-r--r-- | examples/declarative/extending/adding/person.h | 27 |
6 files changed, 103 insertions, 0 deletions
diff --git a/examples/declarative/extending/adding/adding.pro b/examples/declarative/extending/adding/adding.pro new file mode 100644 index 0000000..c02a35f --- /dev/null +++ b/examples/declarative/extending/adding/adding.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = adding +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp \ + person.cpp +HEADERS += person.h +RESOURCES += adding.qrc diff --git a/examples/declarative/extending/adding/adding.qrc b/examples/declarative/extending/adding/adding.qrc new file mode 100644 index 0000000..e2fa01d --- /dev/null +++ b/examples/declarative/extending/adding/adding.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>example.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/extending/adding/example.qml b/examples/declarative/extending/adding/example.qml new file mode 100644 index 0000000..ba7af7a --- /dev/null +++ b/examples/declarative/extending/adding/example.qml @@ -0,0 +1,8 @@ +import Qt 4.6 + +// ![0] +Person { + name: "Bob Jones" + shoeSize: 12 +} +// ![0] diff --git a/examples/declarative/extending/adding/main.cpp b/examples/declarative/extending/adding/main.cpp new file mode 100644 index 0000000..7e5cbef --- /dev/null +++ b/examples/declarative/extending/adding/main.cpp @@ -0,0 +1,22 @@ +#include <QCoreApplication> +#include <QmlEngine> +#include <QmlComponent> +#include <QDebug> +#include "person.h" + +int main(int argc, char ** argv) +{ + QCoreApplication app(argc, argv); + + QmlEngine engine; + QmlComponent component(&engine, ":example.qml"); + Person *person = qobject_cast<Person *>(component.create()); + if (person) { + qWarning() << "The person's name is" << person->name(); + qWarning() << "They wear a" << person->shoeSize() << "sized shoe"; + } else { + qWarning() << "An error occured"; + } + + return 0; +} diff --git a/examples/declarative/extending/adding/person.cpp b/examples/declarative/extending/adding/person.cpp new file mode 100644 index 0000000..ccf08b3 --- /dev/null +++ b/examples/declarative/extending/adding/person.cpp @@ -0,0 +1,30 @@ +#include "person.h" + +// ![0] +Person::Person(QObject *parent) +: QObject(parent), m_shoeSize(0) +{ +} + +QString Person::name() const +{ + return m_name; +} + +void Person::setName(const QString &n) +{ + m_name = n; +} + +int Person::shoeSize() const +{ + return m_shoeSize; +} + +void Person::setShoeSize(int s) +{ + m_shoeSize = s; +} + +QML_DEFINE_TYPE(People, 1, 0, 0, Person, Person); +// ![0] diff --git a/examples/declarative/extending/adding/person.h b/examples/declarative/extending/adding/person.h new file mode 100644 index 0000000..3bef2d4 --- /dev/null +++ b/examples/declarative/extending/adding/person.h @@ -0,0 +1,27 @@ +#ifndef PERSON_H +#define PERSON_H + +#include <QObject> +// ![0] +#include <qml.h> + +class Person : public QObject { +Q_OBJECT +Q_PROPERTY(QString name READ name WRITE setName) +Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) +public: + Person(QObject *parent = 0); + + QString name() const; + void setName(const QString &); + + int shoeSize() const; + void setShoeSize(int); +private: + QString m_name; + int m_shoeSize; +}; +QML_DECLARE_TYPE(Person); +// ![0] + +#endif // PERSON_H |