aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml/referenceexamples/signal
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qml/referenceexamples/signal')
-rw-r--r--examples/qml/referenceexamples/signal/CMakeLists.txt25
-rw-r--r--examples/qml/referenceexamples/signal/birthdayparty.cpp20
-rw-r--r--examples/qml/referenceexamples/signal/birthdayparty.h10
-rw-r--r--examples/qml/referenceexamples/signal/main.cpp12
-rw-r--r--examples/qml/referenceexamples/signal/person.cpp26
-rw-r--r--examples/qml/referenceexamples/signal/person.h16
6 files changed, 33 insertions, 76 deletions
diff --git a/examples/qml/referenceexamples/signal/CMakeLists.txt b/examples/qml/referenceexamples/signal/CMakeLists.txt
index b309efc576..23e494f7c9 100644
--- a/examples/qml/referenceexamples/signal/CMakeLists.txt
+++ b/examples/qml/referenceexamples/signal/CMakeLists.txt
@@ -1,6 +1,6 @@
# Generated from signal.pro.
-cmake_minimum_required(VERSION 3.14)
+cmake_minimum_required(VERSION 3.16)
project(signal LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
@@ -34,17 +34,11 @@ target_link_libraries(signal PUBLIC
Qt::Qml
)
-
-# Resources:
-set(signal_resource_files
- "example.qml"
-)
-
-qt6_add_resources(signal "signal"
- PREFIX
- "/"
- FILES
- ${signal_resource_files}
+qt_add_qml_module(signal
+ URI People
+ VERSION 1.0
+ QML_FILES example.qml
+ NO_RESOURCE_TARGET_PATH
)
install(TARGETS signal
@@ -52,10 +46,3 @@ install(TARGETS signal
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
)
-
-set_target_properties(signal PROPERTIES
- QT_QML_MODULE_VERSION 1.0
- QT_QML_MODULE_URI People
-)
-
-qt6_qml_type_registration(signal)
diff --git a/examples/qml/referenceexamples/signal/birthdayparty.cpp b/examples/qml/referenceexamples/signal/birthdayparty.cpp
index 215c09782a..27498c9cc9 100644
--- a/examples/qml/referenceexamples/signal/birthdayparty.cpp
+++ b/examples/qml/referenceexamples/signal/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,16 +47,12 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#include "birthdayparty.h"
-BirthdayPartyAttached::BirthdayPartyAttached(QObject *object)
-: QObject(object)
-{
-}
+#include "birthdayparty.h"
QDate BirthdayPartyAttached::rsvp() const
{
- return m_rsvp;
+ return m_rsvp;
}
void BirthdayPartyAttached::setRsvp(QDate d)
@@ -64,12 +60,6 @@ void BirthdayPartyAttached::setRsvp(QDate d)
m_rsvp = d;
}
-
-BirthdayParty::BirthdayParty(QObject *parent)
-: QObject(parent), m_host(nullptr)
-{
-}
-
Person *BirthdayParty::host() const
{
return m_host;
@@ -85,12 +75,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/signal/birthdayparty.h b/examples/qml/referenceexamples/signal/birthdayparty.h
index 6d7e022df0..c4a4da5dfb 100644
--- a/examples/qml/referenceexamples/signal/birthdayparty.h
+++ b/examples/qml/referenceexamples/signal/birthdayparty.h
@@ -61,7 +61,7 @@ class BirthdayPartyAttached : public QObject
Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp)
QML_ANONYMOUS
public:
- BirthdayPartyAttached(QObject *object);
+ using QObject::QObject;
QDate rsvp() const;
void setRsvp(QDate);
@@ -79,14 +79,14 @@ class BirthdayParty : public QObject
QML_ELEMENT
QML_ATTACHED(BirthdayPartyAttached)
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;
static BirthdayPartyAttached *qmlAttachedProperties(QObject *);
@@ -97,7 +97,7 @@ signals:
// ![0]
private:
- Person *m_host;
+ Person *m_host = nullptr;
QList<Person *> m_guests;
};
diff --git a/examples/qml/referenceexamples/signal/main.cpp b/examples/qml/referenceexamples/signal/main.cpp
index 7ef3595a8c..d0b060d8e6 100644
--- a/examples/qml/referenceexamples/signal/main.cpp
+++ b/examples/qml/referenceexamples/signal/main.cpp
@@ -63,14 +63,14 @@ 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) {
+ for (qsizetype ii = 0; ii < party->guestCount(); ++ii) {
Person *guest = party->guest(ii);
QDate rsvpDate;
@@ -80,9 +80,9 @@ int main(int argc, char ** argv)
rsvpDate = attached->property("rsvp").toDate();
if (rsvpDate.isNull())
- qWarning() << " " << guest->name() << "RSVP date: Hasn't RSVP'd";
+ qInfo() << " " << guest->name() << "RSVP date: Hasn't RSVP'd";
else
- qWarning() << " " << guest->name() << "RSVP date:" << qPrintable(rsvpDate.toString());
+ qInfo() << " " << guest->name() << "RSVP date:" << rsvpDate.toString();
}
party->startParty();
diff --git a/examples/qml/referenceexamples/signal/person.cpp b/examples/qml/referenceexamples/signal/person.cpp
index 0603644108..4e52da76c8 100644
--- a/examples/qml/referenceexamples/signal/person.cpp
+++ b/examples/qml/referenceexamples/signal/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"
-ShoeDescription::ShoeDescription(QObject *parent)
-: QObject(parent), m_size(0), m_price(0)
-{
-}
+#include "person.h"
int ShoeDescription::size() const
{
@@ -94,11 +90,6 @@ void ShoeDescription::setPrice(qreal p)
m_price = p;
}
-Person::Person(QObject *parent)
-: QObject(parent)
-{
-}
-
QString Person::name() const
{
return m_name;
@@ -113,16 +104,3 @@ ShoeDescription *Person::shoe()
{
return &m_shoe;
}
-
-
-Boy::Boy(QObject * parent)
-: Person(parent)
-{
-}
-
-
-Girl::Girl(QObject * parent)
-: Person(parent)
-{
-}
-
diff --git a/examples/qml/referenceexamples/signal/person.h b/examples/qml/referenceexamples/signal/person.h
index 7283f39f61..ddd3baa5f2 100644
--- a/examples/qml/referenceexamples/signal/person.h
+++ b/examples/qml/referenceexamples/signal/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
@@ -63,7 +64,7 @@ class ShoeDescription : public QObject
Q_PROPERTY(qreal price READ price WRITE setPrice)
QML_ANONYMOUS
public:
- ShoeDescription(QObject *parent = nullptr);
+ using QObject::QObject;
int size() const;
void setSize(int);
@@ -76,11 +77,12 @@ public:
qreal price() const;
void setPrice(qreal);
+
private:
- int m_size;
+ int m_size = 0;
QColor m_color;
QString m_brand;
- qreal m_price;
+ qreal m_price = 0;
};
class Person : public QObject
@@ -90,7 +92,7 @@ class Person : public QObject
Q_PROPERTY(ShoeDescription *shoe READ shoe)
QML_ANONYMOUS
public:
- Person(QObject *parent = nullptr);
+ using QObject::QObject;
QString name() const;
void setName(const QString &);
@@ -106,7 +108,7 @@ class Boy : public Person
Q_OBJECT
QML_ELEMENT
public:
- Boy(QObject * parent = nullptr);
+ using Person::Person;
};
class Girl : public Person
@@ -114,7 +116,7 @@ class Girl : public Person
Q_OBJECT
QML_ELEMENT
public:
- Girl(QObject * parent = nullptr);
+ using Person::Person;
};
#endif // PERSON_H