diff options
author | Olivier De Cannière <olivier.decanniere@qt.io> | 2023-03-17 15:42:47 +0100 |
---|---|---|
committer | Olivier De Cannière <olivier.decanniere@qt.io> | 2023-03-30 18:02:16 +0200 |
commit | 405bd4299819e39397cea0090a9442fd4b6ce911 (patch) | |
tree | c1254e18a8ab47cc6bde048eb52ad0d89c2492c8 /examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/main.cpp | |
parent | 03ff348b4942ae29dd5bc2bd563998d7ba82ecd7 (diff) | |
download | qtdeclarative-405bd4299819e39397cea0090a9442fd4b6ce911.tar.gz |
Doc: Revamp "Extending QML" examples into a tutorial
The examples in the "Extending QML" series were often redundant with the
information of the "Writing QML Extensions with C++" tutorial, had
outdated code and sometimes had no documentation. The examples that
covered topics not mentioned in the first tutorial were revamped into a
second "advanced" tutorial extending the first one. The others were
removed. The remaining examples were largely based on the same example
code of a birthday party. This code was slightly adapted and separated
into 7 states, each building upon the previous, with the code change
illustrating the associated feature. A tutorial page, in the style of
the first one, was added documenting the different QML features and
the required code changes in the example project.
Links in the documentation from and to the affected pages were update
as best as possible.
Pick-to: 6.5
Fixes: QTBUG-111033
Change-Id: I9d97e8b32b128c1624d67525996fa14d493909d3
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/main.cpp')
-rw-r--r-- | examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/main.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/main.cpp b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/main.cpp new file mode 100644 index 0000000000..6d67b6179e --- /dev/null +++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/main.cpp @@ -0,0 +1,49 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include "birthdayparty.h" +#include "person.h" + +#include <QCoreApplication> +#include <QDebug> +#include <QQmlComponent> +#include <QQmlEngine> + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadFromModule("People", "Main"); + std::unique_ptr<BirthdayParty> party{ qobject_cast<BirthdayParty *>(component.create()) }; + + if (party && party->host()) { + qInfo() << party->host()->name() << "is having a birthday!"; + + if (qobject_cast<Boy *>(party->host())) + qInfo() << "He is inviting:"; + else + qInfo() << "She is inviting:"; + + for (qsizetype ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); + + QDate rsvpDate; + QObject *attached = qmlAttachedPropertiesObject<BirthdayParty>(guest, false); + if (attached) + rsvpDate = attached->property("rsvp").toDate(); + + if (rsvpDate.isNull()) + qInfo() << " " << guest->name() << "RSVP date: Hasn't RSVP'd"; + else + qInfo() << " " << guest->name() << "RSVP date:" << rsvpDate.toString(); + } + + party->startParty(); + return QCoreApplication::exec(); + } + + qWarning() << component.errors(); + return EXIT_FAILURE; +} |