aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml/referenceexamples/methods
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qml/referenceexamples/methods')
-rw-r--r--examples/qml/referenceexamples/methods/birthdayparty.cpp12
-rw-r--r--examples/qml/referenceexamples/methods/birthdayparty.h11
-rw-r--r--examples/qml/referenceexamples/methods/main.cpp11
-rw-r--r--examples/qml/referenceexamples/methods/person.cpp9
-rw-r--r--examples/qml/referenceexamples/methods/person.h8
5 files changed, 23 insertions, 28 deletions
diff --git a/examples/qml/referenceexamples/methods/birthdayparty.cpp b/examples/qml/referenceexamples/methods/birthdayparty.cpp
index 4b30d31aeb..1308a09b72 100644
--- a/examples/qml/referenceexamples/methods/birthdayparty.cpp
+++ b/examples/qml/referenceexamples/methods/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"
// ![0]
Person *BirthdayParty::host() const
@@ -70,12 +66,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/methods/birthdayparty.h b/examples/qml/referenceexamples/methods/birthdayparty.h
index 5c2f3c9def..b43308ac8f 100644
--- a/examples/qml/referenceexamples/methods/birthdayparty.h
+++ b/examples/qml/referenceexamples/methods/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
@@ -61,21 +62,21 @@ class BirthdayParty : public QObject
Q_PROPERTY(QQmlListProperty<Person> guests READ 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;
// ![0]
Q_INVOKABLE void invite(const QString &name);
// ![0]
private:
- Person *m_host;
+ Person *m_host = nullptr;
QList<Person *> m_guests;
};
diff --git a/examples/qml/referenceexamples/methods/main.cpp b/examples/qml/referenceexamples/methods/main.cpp
index e30e1d9fb1..32eb4831cc 100644
--- a/examples/qml/referenceexamples/methods/main.cpp
+++ b/examples/qml/referenceexamples/methods/main.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,6 +47,7 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
#include <QCoreApplication>
#include <QQmlEngine>
#include <QQmlComponent>
@@ -63,10 +64,10 @@ 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!";
- qWarning() << "They are inviting:";
- for (int ii = 0; ii < party->guestCount(); ++ii)
- qWarning() << " " << party->guest(ii)->name();
+ qInfo() << party->host()->name() << "is having a birthday!"
+ << "\nThey are inviting:";
+ for (qsizetype ii = 0; ii < party->guestCount(); ++ii)
+ qInfo() << " " << party->guest(ii)->name();
return EXIT_SUCCESS;
}
diff --git a/examples/qml/referenceexamples/methods/person.cpp b/examples/qml/referenceexamples/methods/person.cpp
index 7712363ebf..e2847a2682 100644
--- a/examples/qml/referenceexamples/methods/person.cpp
+++ b/examples/qml/referenceexamples/methods/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,4 +69,3 @@ void Person::setShoeSize(int s)
{
m_shoeSize = s;
}
-
diff --git a/examples/qml/referenceexamples/methods/person.h b/examples/qml/referenceexamples/methods/person.h
index 2407fbb1b9..0849d1ee8c 100644
--- a/examples/qml/referenceexamples/methods/person.h
+++ b/examples/qml/referenceexamples/methods/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,16 +61,17 @@ class Person : public QObject
Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize)
QML_ELEMENT
public:
- Person(QObject *parent = nullptr);
+ using QObject::QObject;
QString name() const;
void setName(const QString &);
int shoeSize() const;
void setShoeSize(int);
+
private:
QString m_name;
- int m_shoeSize;
+ int m_shoeSize = 0;
};
#endif // PERSON_H