diff options
Diffstat (limited to 'examples/qml/referenceexamples/default')
-rw-r--r-- | examples/qml/referenceexamples/default/birthdayparty.cpp | 12 | ||||
-rw-r--r-- | examples/qml/referenceexamples/default/birthdayparty.h | 11 | ||||
-rw-r--r-- | examples/qml/referenceexamples/default/main.cpp | 10 | ||||
-rw-r--r-- | examples/qml/referenceexamples/default/person.cpp | 21 | ||||
-rw-r--r-- | examples/qml/referenceexamples/default/person.h | 11 |
5 files changed, 23 insertions, 42 deletions
diff --git a/examples/qml/referenceexamples/default/birthdayparty.cpp b/examples/qml/referenceexamples/default/birthdayparty.cpp index 81db8ab1b8..aeaf6fbd9c 100644 --- a/examples/qml/referenceexamples/default/birthdayparty.cpp +++ b/examples/qml/referenceexamples/default/birthdayparty.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "birthdayparty.h" -BirthdayParty::BirthdayParty(QObject *parent) -: QObject(parent), m_host(nullptr) -{ -} +#include "birthdayparty.h" Person *BirthdayParty::host() const { @@ -69,12 +65,12 @@ QQmlListProperty<Person> BirthdayParty::guests() return {this, &m_guests}; } -int BirthdayParty::guestCount() const +qsizetype BirthdayParty::guestCount() const { return m_guests.count(); } -Person *BirthdayParty::guest(int index) const +Person *BirthdayParty::guest(qsizetype index) const { return m_guests.at(index); } diff --git a/examples/qml/referenceexamples/default/birthdayparty.h b/examples/qml/referenceexamples/default/birthdayparty.h index 5eb6c88763..cb12a1510b 100644 --- a/examples/qml/referenceexamples/default/birthdayparty.h +++ b/examples/qml/referenceexamples/default/birthdayparty.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef BIRTHDAYPARTY_H #define BIRTHDAYPARTY_H @@ -63,17 +64,17 @@ class BirthdayParty : public QObject Q_CLASSINFO("DefaultProperty", "guests") QML_ELEMENT public: - BirthdayParty(QObject *parent = nullptr); + using QObject::QObject; Person *host() const; void setHost(Person *); QQmlListProperty<Person> guests(); - int guestCount() const; - Person *guest(int) const; + qsizetype guestCount() const; + Person *guest(qsizetype) const; private: - Person *m_host; + Person *m_host = nullptr; QList<Person *> m_guests; }; // ![0] diff --git a/examples/qml/referenceexamples/default/main.cpp b/examples/qml/referenceexamples/default/main.cpp index 6b47d0d4c4..82e6f5ba37 100644 --- a/examples/qml/referenceexamples/default/main.cpp +++ b/examples/qml/referenceexamples/default/main.cpp @@ -63,15 +63,15 @@ int main(int argc, char ** argv) auto *party = qobject_cast<BirthdayParty *>(component.create()); if (party && party->host()) { - qWarning() << party->host()->name() << "is having a birthday!"; + qInfo() << party->host()->name() << "is having a birthday!"; if (qobject_cast<Boy *>(party->host())) - qWarning() << "He is inviting:"; + qInfo() << "He is inviting:"; else - qWarning() << "She is inviting:"; + qInfo() << "She is inviting:"; - for (int ii = 0; ii < party->guestCount(); ++ii) - qWarning() << " " << party->guest(ii)->name(); + for (qsizetype ii = 0; ii < party->guestCount(); ++ii) + qInfo() << " " << party->guest(ii)->name(); return EXIT_SUCCESS; } diff --git a/examples/qml/referenceexamples/default/person.cpp b/examples/qml/referenceexamples/default/person.cpp index a1d887a4d0..e2847a2682 100644 --- a/examples/qml/referenceexamples/default/person.cpp +++ b/examples/qml/referenceexamples/default/person.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,12 +47,8 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "person.h" -Person::Person(QObject *parent) -: QObject(parent), m_shoeSize(0) -{ -} +#include "person.h" QString Person::name() const { @@ -73,16 +69,3 @@ void Person::setShoeSize(int s) { m_shoeSize = s; } - - -Boy::Boy(QObject * parent) -: Person(parent) -{ -} - - -Girl::Girl(QObject * parent) -: Person(parent) -{ -} - diff --git a/examples/qml/referenceexamples/default/person.h b/examples/qml/referenceexamples/default/person.h index 361a89c599..0b2e280747 100644 --- a/examples/qml/referenceexamples/default/person.h +++ b/examples/qml/referenceexamples/default/person.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #ifndef PERSON_H #define PERSON_H @@ -60,7 +61,7 @@ class Person : public QObject Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) QML_ANONYMOUS public: - Person(QObject *parent = nullptr); + using QObject::QObject; QString name() const; void setName(const QString &); @@ -69,7 +70,7 @@ public: void setShoeSize(int); private: QString m_name; - int m_shoeSize; + int m_shoeSize = 0; }; class Boy : public Person @@ -77,7 +78,7 @@ class Boy : public Person Q_OBJECT QML_ELEMENT public: - Boy(QObject * parent = nullptr); + using Person::Person; }; class Girl : public Person @@ -85,7 +86,7 @@ class Girl : public Person Q_OBJECT QML_ELEMENT public: - Girl(QObject * parent = nullptr); + using Person::Person; }; #endif // PERSON_H |