diff options
Diffstat (limited to 'examples/qml')
98 files changed, 637 insertions, 301 deletions
diff --git a/examples/qml/doc/src/qml-extending.qdoc b/examples/qml/doc/src/qml-extending.qdoc index e56dd90dd7..723e470d45 100644 --- a/examples/qml/doc/src/qml-extending.qdoc +++ b/examples/qml/doc/src/qml-extending.qdoc @@ -52,10 +52,6 @@ type, the C++ class can be named differently, or appear in a namespace. The Person class implementation is quite basic. The property accessors simply return members of the object instance. -The \c main.cpp file also calls the \c qmlRegisterType() function to -register the \c Person type with QML as a type in the People library version 1.0, -and defines the mapping between the C++ and QML class names. - \section1 Running the Example The main.cpp file in the example includes a simple shell application that @@ -73,13 +69,15 @@ This example builds on: \li \l {Extending QML - Adding Types Example} \endlist -Shows how to use \l {QQmlEngine::}{qmlRegisterExtendedType()} to provide an +Shows how to use \l {QML_EXTENDED} to provide an \l {Registering Extension Objects}{extension object} to a \l QLineEdit without modifying or subclassing it. -Firstly, the LineEditExtension class is registered with the QML system as an extension of QLineEdit: +Firstly, the LineEditExtension class is registered with the QML system as an +extension of QLineEdit. We declare a foreign type to do this as we cannot modify +Qt's internal QLineEdit class. -\snippet referenceexamples/extended/main.cpp 0 +\snippet referenceexamples/extended/lineedit.h 0 The QML engine then instantiates a \l QLineEdit: @@ -178,11 +176,12 @@ previous example. However, as we have repurposed the People class as a common base for Boy and Girl, we want to prevent it from being instantiated from QML directly - an explicit Boy or Girl should be instantiated instead. -\snippet referenceexamples/coercion/main.cpp 0 +\snippet referenceexamples/coercion/person.h 0 While we want to disallow instantiating Person from within QML, it still needs to be registered with the QML engine, so that it can be used as a property type -and other types can be coerced to it. +and other types can be coerced to it. This is what the QML_UNCREATABLE macro +does. \section2 Define Boy and Girl diff --git a/examples/qml/dynamicscene/dynamicscene.pro b/examples/qml/dynamicscene/dynamicscene.pro new file mode 100644 index 0000000000..29a3fa97e2 --- /dev/null +++ b/examples/qml/dynamicscene/dynamicscene.pro @@ -0,0 +1,9 @@ +TEMPLATE = app + +QT += quick qml +SOURCES += main.cpp + +RESOURCES += dynamicscene.qrc + +target.path = $$[QT_INSTALL_EXAMPLES]/qml/dynamicscene +INSTALLS += target diff --git a/examples/qml/dynamicscene/dynamicscene.qrc b/examples/qml/dynamicscene/dynamicscene.qrc new file mode 100644 index 0000000000..ac9baa4941 --- /dev/null +++ b/examples/qml/dynamicscene/dynamicscene.qrc @@ -0,0 +1,19 @@ +<RCC> + <qresource prefix="/"> + <file>dynamicscene.qml</file> + <file>content/images/face-smile.png</file> + <file>content/images/moon.png</file> + <file>content/images/NOTE</file> + <file>content/images/rabbit_brown.png</file> + <file>content/images/rabbit_bw.png</file> + <file>content/images/star.png</file> + <file>content/images/sun.png</file> + <file>content/images/tree_s.png</file> + <file>content/Button.qml</file> + <file>content/GenericSceneItem.qml</file> + <file>content/itemCreation.js</file> + <file>content/PaletteItem.qml</file> + <file>content/PerspectiveItem.qml</file> + <file>content/Sun.qml</file> + </qresource> +</RCC> diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.cpp b/examples/qml/dynamicscene/main.cpp index ce8b95b6b6..e28375158d 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.cpp +++ b/examples/qml/dynamicscene/main.cpp @@ -1,9 +1,9 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** -** This file is part of the documentation of the Qt Toolkit. +** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** Commercial License Usage @@ -47,17 +47,5 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "chartsplugin.h" -//![0] -#include "piechart.h" -#include "pieslice.h" -#include <qqml.h> - -void ChartsPlugin::registerTypes(const char *uri) -{ - qmlRegisterType<PieChart>(uri, 1, 0, "PieChart"); - qmlRegisterType<PieSlice>(uri, 1, 0, "PieSlice"); -} - -//![0] - +#include "../../quick/shared/shared.h" +DECLARATIVE_EXAMPLE_MAIN(dynamicscene) diff --git a/examples/qml/qml-i18n/doc/src/i18n.qdoc b/examples/qml/qml-i18n/doc/src/i18n.qdoc index dbc4efa58c..48946aac9c 100644 --- a/examples/qml/qml-i18n/doc/src/i18n.qdoc +++ b/examples/qml/qml-i18n/doc/src/i18n.qdoc @@ -52,4 +52,6 @@ lrelease i18n/*.ts \endcode +\note On Android, please make sure to include the generated *.qm files as resources. + */ diff --git a/examples/qml/qml-i18n/i18n/base.ts b/examples/qml/qml-i18n/i18n/base.ts index 77c640f370..99ceeeb016 100644 --- a/examples/qml/qml-i18n/i18n/base.ts +++ b/examples/qml/qml-i18n/i18n/base.ts @@ -4,7 +4,7 @@ <context> <name>qml-i18n</name> <message> - <location filename="../qml-i18n.qml" line="66"/> + <location filename="../qml-i18n.qml" line="68"/> <source>Hello</source> <translation type="unfinished"></translation> </message> diff --git a/examples/qml/qml-i18n/i18n/qml_en_AU.ts b/examples/qml/qml-i18n/i18n/qml_en_AU.ts index 86ccfb7bf8..feb4f9e9c0 100644 --- a/examples/qml/qml-i18n/i18n/qml_en_AU.ts +++ b/examples/qml/qml-i18n/i18n/qml_en_AU.ts @@ -4,7 +4,7 @@ <context> <name>qml-i18n</name> <message> - <location filename="../qml-i18n.qml" line="66"/> + <location filename="../qml-i18n.qml" line="68"/> <source>Hello</source> <translation>G'day</translation> </message> diff --git a/examples/qml/qml-i18n/i18n/qml_fr.ts b/examples/qml/qml-i18n/i18n/qml_fr.ts index 363bebb395..c4872e63d0 100644 --- a/examples/qml/qml-i18n/i18n/qml_fr.ts +++ b/examples/qml/qml-i18n/i18n/qml_fr.ts @@ -4,7 +4,7 @@ <context> <name>qml-i18n</name> <message> - <location filename="../qml-i18n.qml" line="66"/> + <location filename="../qml-i18n.qml" line="68"/> <source>Hello</source> <translation>Bonjour</translation> </message> diff --git a/examples/qml/qml-i18n/main.cpp b/examples/qml/qml-i18n/main.cpp new file mode 100644 index 0000000000..0680dc8b41 --- /dev/null +++ b/examples/qml/qml-i18n/main.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QGuiApplication> +#include <QQmlApplicationEngine> + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication app(argc, argv); + QQmlApplicationEngine engine; + const QUrl url(QStringLiteral("qrc:/qml-i18n.qml")); + + QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, + &app, [url](QObject *obj, const QUrl &objUrl) { + if (!obj && url == objUrl) + QCoreApplication::exit(-1); + }, Qt::QueuedConnection); + engine.load(url); + + return app.exec(); +} diff --git a/examples/qml/qml-i18n/qml-i18n.pro b/examples/qml/qml-i18n/qml-i18n.pro new file mode 100644 index 0000000000..847c741b00 --- /dev/null +++ b/examples/qml/qml-i18n/qml-i18n.pro @@ -0,0 +1,17 @@ +TEMPLATE = app + +QT += quick qml +SOURCES += main.cpp + +RESOURCES += qml-i18n.qrc + +target.path = $$[QT_INSTALL_EXAMPLES]/qml/qml-i18n +INSTALLS += target + +CONFIG += lrelease embed_translations + +TRANSLATIONS += \ + i18n/base.ts \ + i18n/qml_en.ts \ + i18n/qml_en_AU.ts \ + i18n/qml_fr.ts diff --git a/examples/qml/qml-i18n/qml-i18n.qml b/examples/qml/qml-i18n/qml-i18n.qml index 217ffb56ae..85c4c44160 100644 --- a/examples/qml/qml-i18n/qml-i18n.qml +++ b/examples/qml/qml-i18n/qml-i18n.qml @@ -48,17 +48,19 @@ ** ****************************************************************************/ -import QtQuick 2.0 +import QtQuick 2.12 +import QtQuick.Window 2.12 -Rectangle { +Window { + visible: true width: 640; height: 480 Column { anchors.fill: parent; spacing: 20 Text { - text: "If a translation is available for the system language (eg. French) then the "+ - "string below will translated (eg. 'Bonjour'). Otherwise it will show 'Hello'." + text: "If a translation is available for the system language (eg. French) then the " + + "string below will be translated (eg. 'Bonjour'). Otherwise it will show 'Hello'." width: parent.width; wrapMode: Text.WordWrap } diff --git a/examples/qml/qml-i18n/qml-i18n.qrc b/examples/qml/qml-i18n/qml-i18n.qrc new file mode 100644 index 0000000000..3a505b1665 --- /dev/null +++ b/examples/qml/qml-i18n/qml-i18n.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>qml-i18n.qml</file> + </qresource> +</RCC> diff --git a/examples/qml/qmlextensionplugins/doc/src/qmlpluginex.qdoc b/examples/qml/qmlextensionplugins/doc/src/qmlpluginex.qdoc index 9e0bbb1815..24d6991d52 100644 --- a/examples/qml/qmlextensionplugins/doc/src/qmlpluginex.qdoc +++ b/examples/qml/qmlextensionplugins/doc/src/qmlpluginex.qdoc @@ -29,7 +29,7 @@ \title QML Plugin Example \example qmlextensionplugins - \brief This example creates a C++ plugin extension by subclassing QQmlExtensionPlugin. + \brief This example creates a C++ plugin extension by subclassing QQmlEngineExtensionPlugin. \image qml-plugins-example.png diff --git a/examples/qml/qmlextensionplugins/plugin.cpp b/examples/qml/qmlextensionplugins/plugin.cpp index 4866106e4a..ae5f35bf5f 100644 --- a/examples/qml/qmlextensionplugins/plugin.cpp +++ b/examples/qml/qmlextensionplugins/plugin.cpp @@ -48,117 +48,14 @@ ** ****************************************************************************/ -#include <QtQml/QQmlExtensionPlugin> -#include <QtQml/qqml.h> +#include <QtQml/QQmlEngineExtensionPlugin> #include <qdebug.h> -#include <qdatetime.h> -#include <qbasictimer.h> -#include <qcoreapplication.h> - -// Implements a "TimeModel" class with hour and minute properties -// that change on-the-minute yet efficiently sleep the rest -// of the time. - -class MinuteTimer : public QObject -{ - Q_OBJECT -public: - MinuteTimer(QObject *parent) : QObject(parent) - { - } - - void start() - { - if (!timer.isActive()) { - time = QTime::currentTime(); - timer.start(60000-time.second()*1000, this); - } - } - - void stop() - { - timer.stop(); - } - - int hour() const { return time.hour(); } - int minute() const { return time.minute(); } - -signals: - void timeChanged(); - -protected: - void timerEvent(QTimerEvent *) override - { - QTime now = QTime::currentTime(); - if (now.second() == 59 && now.minute() == time.minute() && now.hour() == time.hour()) { - // just missed time tick over, force it, wait extra 0.5 seconds - time = time.addSecs(60); - timer.start(60500, this); - } else { - time = now; - timer.start(60000-time.second()*1000, this); - } - emit timeChanged(); - } - -private: - QTime time; - QBasicTimer timer; -}; - -//![0] -class TimeModel : public QObject -{ - Q_OBJECT - Q_PROPERTY(int hour READ hour NOTIFY timeChanged) - Q_PROPERTY(int minute READ minute NOTIFY timeChanged) -//![0] - -public: - TimeModel(QObject *parent=nullptr) : QObject(parent) - { - if (++instances == 1) { - if (!timer) - timer = new MinuteTimer(QCoreApplication::instance()); - connect(timer, &MinuteTimer::timeChanged, this, &TimeModel::timeChanged); - timer->start(); - } - } - - ~TimeModel() override - { - if (--instances == 0) { - timer->stop(); - } - } - - int minute() const { return timer->minute(); } - int hour() const { return timer->hour(); } - -signals: - void timeChanged(); - -private: - QTime t; - static MinuteTimer *timer; - static int instances; -}; - -int TimeModel::instances=0; -MinuteTimer *TimeModel::timer=nullptr; //![plugin] -class QExampleQmlPlugin : public QQmlExtensionPlugin +class QExampleQmlPlugin : public QQmlEngineExtensionPlugin { Q_OBJECT - Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) - -public: - void registerTypes(const char *uri) override - { - Q_ASSERT(uri == QLatin1String("TimeExample")); - qmlRegisterType<TimeModel>(uri, 1, 0, "Time"); - } + Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) }; //![plugin] diff --git a/examples/qml/qmlextensionplugins/plugins.qmlproject b/examples/qml/qmlextensionplugins/plugins.qmlproject index 771ab45b66..c2de5f5703 100644 --- a/examples/qml/qmlextensionplugins/plugins.qmlproject +++ b/examples/qml/qmlextensionplugins/plugins.qmlproject @@ -13,4 +13,6 @@ Project { ImageFiles { directory: "." } + + importPaths: [ "imports" ] } diff --git a/examples/qml/qmlextensionplugins/qmlextensionplugins.pro b/examples/qml/qmlextensionplugins/qmlextensionplugins.pro index 946626cce7..c074b8d671 100644 --- a/examples/qml/qmlextensionplugins/qmlextensionplugins.pro +++ b/examples/qml/qmlextensionplugins/qmlextensionplugins.pro @@ -1,25 +1,46 @@ TEMPLATE = lib -CONFIG += plugin +CONFIG += plugin qmltypes QT += qml -DESTDIR = imports/TimeExample +QML_IMPORT_NAME = TimeExample +QML_IMPORT_MAJOR_VERSION = 1 + +DESTDIR = imports/$$QML_IMPORT_NAME TARGET = qmlqtimeexampleplugin +QMLTYPES_FILENAME = $$DESTDIR/plugins.qmltypes + +SOURCES += \ + plugin.cpp \ + timemodel.cpp + +HEADERS += \ + timemodel.h + +PLUGINFILES = \ + imports/$$QML_IMPORT_NAME/qmldir \ + imports/$$QML_IMPORT_NAME/center.png \ + imports/$$QML_IMPORT_NAME/clock.png \ + imports/$$QML_IMPORT_NAME/Clock.qml \ + imports/$$QML_IMPORT_NAME/hour.png \ + imports/$$QML_IMPORT_NAME/minute.png + +target.path = $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME + +pluginfiles_copy.files = $$PLUGINFILES +pluginfiles_copy.path = $$DESTDIR + +pluginfiles_install.files = $$PLUGINFILES $$OUT_PWD/$$DESTDIR/plugins.qmltypes +pluginfiles_install.path = $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME -SOURCES += plugin.cpp +qml_copy.files = plugins.qml plugins.qmlproject +qml_copy.path = $$OUT_PWD -pluginfiles.files += \ - imports/TimeExample/qmldir \ - imports/TimeExample/center.png \ - imports/TimeExample/clock.png \ - imports/TimeExample/Clock.qml \ - imports/TimeExample/hour.png \ - imports/TimeExample/minute.png +qml_install.files = plugins.qml plugins.qmlproject +qml_install.path = $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins -qml.files = plugins.qml -qml.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins -target.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/TimeExample -pluginfiles.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/TimeExample +INSTALLS += target qml_install pluginfiles_install +COPIES += qml_copy pluginfiles_copy -INSTALLS += target qml pluginfiles +OTHER_FILES += $$PLUGINFILES plugins.qml CONFIG += install_ok # Do not cargo-cult this! diff --git a/examples/qml/qmlextensionplugins/timemodel.cpp b/examples/qml/qmlextensionplugins/timemodel.cpp new file mode 100644 index 0000000000..af5ccb2988 --- /dev/null +++ b/examples/qml/qmlextensionplugins/timemodel.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "timemodel.h" + +int TimeModel::instances=0; +MinuteTimer *TimeModel::timer=nullptr; + +void MinuteTimer::start() +{ + if (!timer.isActive()) { + time = QTime::currentTime(); + timer.start(60000-time.second()*1000, this); + } +} + +void MinuteTimer::stop() +{ + timer.stop(); +} + +void MinuteTimer::timerEvent(QTimerEvent *) +{ + QTime now = QTime::currentTime(); + if (now.second() == 59 && now.minute() == time.minute() && now.hour() == time.hour()) { + // just missed time tick over, force it, wait extra 0.5 seconds + time = time.addSecs(60); + timer.start(60500, this); + } else { + time = now; + timer.start(60000-time.second()*1000, this); + } + emit timeChanged(); +} + +TimeModel::TimeModel(QObject *parent) : QObject(parent) +{ + if (++instances == 1) { + if (!timer) + timer = new MinuteTimer(QCoreApplication::instance()); + connect(timer, &MinuteTimer::timeChanged, this, &TimeModel::timeChanged); + timer->start(); + } +} + +TimeModel::~TimeModel() +{ + if (--instances == 0) { + timer->stop(); + } +} diff --git a/examples/qml/qmlextensionplugins/timemodel.h b/examples/qml/qmlextensionplugins/timemodel.h new file mode 100644 index 0000000000..bb107aeb71 --- /dev/null +++ b/examples/qml/qmlextensionplugins/timemodel.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TIMEMODEL_H +#define TIMEMODEL_H + +#include <QtQml/qqml.h> +#include <QtCore/qdatetime.h> +#include <QtCore/qbasictimer.h> +#include <QtCore/qcoreapplication.h> + +// Implements a "TimeModel" class with hour and minute properties +// that change on-the-minute yet efficiently sleep the rest +// of the time. + +class MinuteTimer : public QObject +{ + Q_OBJECT +public: + MinuteTimer(QObject *parent) : QObject(parent) {} + + void start(); + void stop(); + + int hour() const { return time.hour(); } + int minute() const { return time.minute(); } + +signals: + void timeChanged(); + +protected: + void timerEvent(QTimerEvent *) override; + +private: + QTime time; + QBasicTimer timer; +}; + +//![0] +class TimeModel : public QObject +{ + Q_OBJECT + Q_PROPERTY(int hour READ hour NOTIFY timeChanged) + Q_PROPERTY(int minute READ minute NOTIFY timeChanged) + QML_NAMED_ELEMENT(Time) +//![0] + +public: + TimeModel(QObject *parent=nullptr); + ~TimeModel() override; + + int minute() const { return timer->minute(); } + int hour() const { return timer->hour(); } + +signals: + void timeChanged(); + +private: + QTime t; + static MinuteTimer *timer; + static int instances; +}; + +#endif // TIMEMODEL_H diff --git a/examples/qml/referenceexamples/adding/adding.pro b/examples/qml/referenceexamples/adding/adding.pro index ae135c7925..a4a677c3c4 100644 --- a/examples/qml/referenceexamples/adding/adding.pro +++ b/examples/qml/referenceexamples/adding/adding.pro @@ -1,4 +1,8 @@ QT = core qml +CONFIG += qmltypes + +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 SOURCES += main.cpp \ person.cpp diff --git a/examples/qml/referenceexamples/adding/main.cpp b/examples/qml/referenceexamples/adding/main.cpp index e312149da1..6c3920f04b 100644 --- a/examples/qml/referenceexamples/adding/main.cpp +++ b/examples/qml/referenceexamples/adding/main.cpp @@ -56,9 +56,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); -//![0] - qmlRegisterType<Person>("People", 1,0, "Person"); -//![0] QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); @@ -70,5 +67,5 @@ int main(int argc, char ** argv) qWarning() << component.errors(); } - return 0; + return EXIT_SUCCESS; } diff --git a/examples/qml/referenceexamples/adding/person.h b/examples/qml/referenceexamples/adding/person.h index f40c8d8086..530c335dee 100644 --- a/examples/qml/referenceexamples/adding/person.h +++ b/examples/qml/referenceexamples/adding/person.h @@ -51,12 +51,15 @@ #define PERSON_H #include <QObject> +#include <QtQml/qqml.h> + //![0] class Person : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) + QML_ELEMENT public: Person(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/attached/attached.pro b/examples/qml/referenceexamples/attached/attached.pro index 16b585bc45..8c66b189f7 100644 --- a/examples/qml/referenceexamples/attached/attached.pro +++ b/examples/qml/referenceexamples/attached/attached.pro @@ -1,4 +1,8 @@ QT += qml +CONFIG += qmltypes + +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 SOURCES += main.cpp \ person.cpp \ diff --git a/examples/qml/referenceexamples/attached/birthdayparty.cpp b/examples/qml/referenceexamples/attached/birthdayparty.cpp index da0cb800fc..888aafbc18 100644 --- a/examples/qml/referenceexamples/attached/birthdayparty.cpp +++ b/examples/qml/referenceexamples/attached/birthdayparty.cpp @@ -81,7 +81,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty<Person> BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/attached/birthdayparty.h b/examples/qml/referenceexamples/attached/birthdayparty.h index 15375f14d9..308d0652a8 100644 --- a/examples/qml/referenceexamples/attached/birthdayparty.h +++ b/examples/qml/referenceexamples/attached/birthdayparty.h @@ -59,6 +59,7 @@ class BirthdayPartyAttached : public QObject { Q_OBJECT Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) + QML_ANONYMOUS public: BirthdayPartyAttached(QObject *object); @@ -75,6 +76,12 @@ class BirthdayParty : public QObject Q_PROPERTY(Person *host READ host WRITE setHost) Q_PROPERTY(QQmlListProperty<Person> guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") + QML_ELEMENT + +//! [declare attached] + QML_ATTACHED(BirthdayPartyAttached) +//! [declare attached] + public: BirthdayParty(QObject *parent = nullptr); @@ -93,7 +100,4 @@ private: QList<Person *> m_guests; }; -//! [declare attached] -QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) -//! [declare attached] #endif // BIRTHDAYPARTY_H diff --git a/examples/qml/referenceexamples/attached/main.cpp b/examples/qml/referenceexamples/attached/main.cpp index 581b033dfc..2fceb98ac9 100644 --- a/examples/qml/referenceexamples/attached/main.cpp +++ b/examples/qml/referenceexamples/attached/main.cpp @@ -58,13 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterType<BirthdayPartyAttached>(); - qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); - qmlRegisterType<ShoeDescription>(); - qmlRegisterType<Person>(); - qmlRegisterType<Boy>("People", 1,0, "Boy"); - qmlRegisterType<Girl>("People", 1,0, "Girl"); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); @@ -93,9 +86,9 @@ int main(int argc, char ** argv) qWarning() << " " << guest->name() << "RSVP date:" << qPrintable(rsvpDate.toString()); } - } else { - qWarning() << component.errors(); + return EXIT_SUCCESS; } - return 0; + qWarning() << component.errors(); + return EXIT_FAILURE; } diff --git a/examples/qml/referenceexamples/attached/person.h b/examples/qml/referenceexamples/attached/person.h index 2398da38bf..239f4405c0 100644 --- a/examples/qml/referenceexamples/attached/person.h +++ b/examples/qml/referenceexamples/attached/person.h @@ -52,6 +52,7 @@ #include <QObject> #include <QColor> +#include <QtQml/qqml.h> class ShoeDescription : public QObject { @@ -60,6 +61,7 @@ class ShoeDescription : public QObject Q_PROPERTY(QColor color READ color WRITE setColor) Q_PROPERTY(QString brand READ brand WRITE setBrand) Q_PROPERTY(qreal price READ price WRITE setPrice) + QML_ANONYMOUS public: ShoeDescription(QObject *parent = 0); @@ -86,6 +88,7 @@ class Person : public QObject Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(ShoeDescription *shoe READ shoe) + QML_ANONYMOUS public: Person(QObject *parent = nullptr); @@ -101,6 +104,7 @@ private: class Boy : public Person { Q_OBJECT + QML_ELEMENT public: Boy(QObject * parent = nullptr); }; @@ -108,6 +112,7 @@ public: class Girl : public Person { Q_OBJECT + QML_ELEMENT public: Girl(QObject * parent = nullptr); }; diff --git a/examples/qml/referenceexamples/binding/binding.pro b/examples/qml/referenceexamples/binding/binding.pro index 636d0a10f1..dce780d0a2 100644 --- a/examples/qml/referenceexamples/binding/binding.pro +++ b/examples/qml/referenceexamples/binding/binding.pro @@ -1,5 +1,9 @@ QT += qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp \ diff --git a/examples/qml/referenceexamples/binding/birthdayparty.cpp b/examples/qml/referenceexamples/binding/birthdayparty.cpp index 866c1f6968..cfedf84be0 100644 --- a/examples/qml/referenceexamples/binding/birthdayparty.cpp +++ b/examples/qml/referenceexamples/binding/birthdayparty.cpp @@ -87,7 +87,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty<Person> BirthdayParty::guests() { - return QQmlListProperty<Person>(this, m_guests); + return QQmlListProperty<Person>(this, &m_guests); } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/binding/birthdayparty.h b/examples/qml/referenceexamples/binding/birthdayparty.h index 15e1908ece..3cd5cf1c9a 100644 --- a/examples/qml/referenceexamples/binding/birthdayparty.h +++ b/examples/qml/referenceexamples/binding/birthdayparty.h @@ -60,6 +60,7 @@ class BirthdayPartyAttached : public QObject { Q_OBJECT Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp NOTIFY rsvpChanged) + QML_ANONYMOUS public: BirthdayPartyAttached(QObject *object); @@ -82,6 +83,8 @@ class BirthdayParty : public QObject Q_PROPERTY(QQmlListProperty<Person> guests READ guests) Q_PROPERTY(QString announcement READ announcement WRITE setAnnouncement) Q_CLASSINFO("DefaultProperty", "guests") + QML_ELEMENT + QML_ATTACHED(BirthdayPartyAttached) public: BirthdayParty(QObject *parent = nullptr); @@ -107,6 +110,4 @@ private: QList<Person *> m_guests; }; -QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) - #endif // BIRTHDAYPARTY_H diff --git a/examples/qml/referenceexamples/binding/example.qml b/examples/qml/referenceexamples/binding/example.qml index a89b4bc02e..b45ef6881b 100644 --- a/examples/qml/referenceexamples/binding/example.qml +++ b/examples/qml/referenceexamples/binding/example.qml @@ -62,7 +62,7 @@ BirthdayParty { shoe { size: 12; color: "white"; brand: "Nike"; price: 90.0 } } // ![0] - onPartyStarted: console.log("This party started rockin' at " + time); + onPartyStarted: (time) => { console.log("This party started rockin' at " + time); } Boy { diff --git a/examples/qml/referenceexamples/binding/happybirthdaysong.h b/examples/qml/referenceexamples/binding/happybirthdaysong.h index dcfebc06ba..c84e9d9e5e 100644 --- a/examples/qml/referenceexamples/binding/happybirthdaysong.h +++ b/examples/qml/referenceexamples/binding/happybirthdaysong.h @@ -52,14 +52,17 @@ #include <QQmlPropertyValueSource> #include <QQmlProperty> +#include <qqml.h> #include <QStringList> +#include <qqml.h> class HappyBirthdaySong : public QObject, public QQmlPropertyValueSource { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) Q_INTERFACES(QQmlPropertyValueSource) + QML_ELEMENT public: HappyBirthdaySong(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/binding/main.cpp b/examples/qml/referenceexamples/binding/main.cpp index 99187eba3e..2e9995fcd8 100644 --- a/examples/qml/referenceexamples/binding/main.cpp +++ b/examples/qml/referenceexamples/binding/main.cpp @@ -58,13 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterType<BirthdayPartyAttached>(); - qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); - qmlRegisterType<HappyBirthdaySong>("People", 1,0, "HappyBirthdaySong"); - qmlRegisterType<ShoeDescription>(); - qmlRegisterType<Person>(); - qmlRegisterType<Boy>("People", 1,0, "Boy"); - qmlRegisterType<Girl>("People", 1,0, "Girl"); QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); @@ -94,9 +87,9 @@ int main(int argc, char ** argv) } party->startParty(); - } else { - qWarning() << component.errors(); + return QCoreApplication::exec(); } - return app.exec(); + qWarning() << component.errors(); + return EXIT_FAILURE; } diff --git a/examples/qml/referenceexamples/binding/person.h b/examples/qml/referenceexamples/binding/person.h index 543b24f971..af9864950a 100644 --- a/examples/qml/referenceexamples/binding/person.h +++ b/examples/qml/referenceexamples/binding/person.h @@ -52,6 +52,7 @@ #include <QObject> #include <QColor> +#include <QtQml/qqml.h> class ShoeDescription : public QObject { @@ -60,6 +61,7 @@ class ShoeDescription : public QObject Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY shoeChanged) Q_PROPERTY(QString brand READ brand WRITE setBrand NOTIFY shoeChanged) Q_PROPERTY(qreal price READ price WRITE setPrice NOTIFY shoeChanged) + QML_ANONYMOUS public: ShoeDescription(QObject *parent = nullptr); @@ -91,6 +93,7 @@ class Person : public QObject // ![0] Q_PROPERTY(ShoeDescription *shoe READ shoe CONSTANT) // ![0] + QML_ANONYMOUS public: Person(QObject *parent = nullptr); @@ -109,6 +112,7 @@ private: class Boy : public Person { Q_OBJECT + QML_ELEMENT public: Boy(QObject * parent = nullptr); }; @@ -116,6 +120,7 @@ public: class Girl : public Person { Q_OBJECT + QML_ELEMENT public: Girl(QObject * parent = nullptr); }; diff --git a/examples/qml/referenceexamples/coercion/birthdayparty.cpp b/examples/qml/referenceexamples/coercion/birthdayparty.cpp index 1bae55076c..81db8ab1b8 100644 --- a/examples/qml/referenceexamples/coercion/birthdayparty.cpp +++ b/examples/qml/referenceexamples/coercion/birthdayparty.cpp @@ -66,7 +66,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty<Person> BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/coercion/birthdayparty.h b/examples/qml/referenceexamples/coercion/birthdayparty.h index 554e7ab0da..ba8b2445f1 100644 --- a/examples/qml/referenceexamples/coercion/birthdayparty.h +++ b/examples/qml/referenceexamples/coercion/birthdayparty.h @@ -60,6 +60,7 @@ class BirthdayParty : public QObject // ![0] Q_PROPERTY(Person *host READ host WRITE setHost) Q_PROPERTY(QQmlListProperty<Person> guests READ guests) + QML_ELEMENT // ![0] public: BirthdayParty(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/coercion/coercion.pro b/examples/qml/referenceexamples/coercion/coercion.pro index 373a15fc28..225fd13e08 100644 --- a/examples/qml/referenceexamples/coercion/coercion.pro +++ b/examples/qml/referenceexamples/coercion/coercion.pro @@ -1,5 +1,9 @@ QT = core qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp diff --git a/examples/qml/referenceexamples/coercion/main.cpp b/examples/qml/referenceexamples/coercion/main.cpp index 262cdf6320..6b47d0d4c4 100644 --- a/examples/qml/referenceexamples/coercion/main.cpp +++ b/examples/qml/referenceexamples/coercion/main.cpp @@ -58,16 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); - //![0] - qmlRegisterType<Person>(); - //![0] - - //![register boy girl] - qmlRegisterType<Boy>("People", 1,0, "Boy"); - qmlRegisterType<Girl>("People", 1,0, "Girl"); - //![register boy girl] - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); @@ -82,9 +72,10 @@ int main(int argc, char ** argv) for (int ii = 0; ii < party->guestCount(); ++ii) qWarning() << " " << party->guest(ii)->name(); - } else { - qWarning() << component.errors(); + + return EXIT_SUCCESS; } - return 0; + qWarning() << component.errors(); + return EXIT_FAILURE; } diff --git a/examples/qml/referenceexamples/coercion/person.h b/examples/qml/referenceexamples/coercion/person.h index 692cf4eb19..7e2828da04 100644 --- a/examples/qml/referenceexamples/coercion/person.h +++ b/examples/qml/referenceexamples/coercion/person.h @@ -51,12 +51,17 @@ #define PERSON_H #include <QObject> +#include <QtQml/qqml.h> class Person : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) + //![0] + QML_ELEMENT + QML_UNCREATABLE("Person is an abstract base class.") + //![0] public: Person(QObject *parent = nullptr); @@ -75,6 +80,7 @@ private: class Boy : public Person { Q_OBJECT + QML_ELEMENT public: Boy(QObject * parent = nullptr); }; @@ -83,6 +89,7 @@ public: class Girl : public Person { Q_OBJECT + QML_ELEMENT public: Girl(QObject * parent = nullptr); }; diff --git a/examples/qml/referenceexamples/default/birthdayparty.cpp b/examples/qml/referenceexamples/default/birthdayparty.cpp index 1bae55076c..81db8ab1b8 100644 --- a/examples/qml/referenceexamples/default/birthdayparty.cpp +++ b/examples/qml/referenceexamples/default/birthdayparty.cpp @@ -66,7 +66,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty<Person> BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/default/birthdayparty.h b/examples/qml/referenceexamples/default/birthdayparty.h index ea63a6a16d..5eb6c88763 100644 --- a/examples/qml/referenceexamples/default/birthdayparty.h +++ b/examples/qml/referenceexamples/default/birthdayparty.h @@ -61,6 +61,7 @@ class BirthdayParty : public QObject Q_PROPERTY(Person *host READ host WRITE setHost) Q_PROPERTY(QQmlListProperty<Person> guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") + QML_ELEMENT public: BirthdayParty(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/default/default.pro b/examples/qml/referenceexamples/default/default.pro index c119ef0d2e..f52f749ddd 100644 --- a/examples/qml/referenceexamples/default/default.pro +++ b/examples/qml/referenceexamples/default/default.pro @@ -1,5 +1,9 @@ QT = core qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp diff --git a/examples/qml/referenceexamples/default/main.cpp b/examples/qml/referenceexamples/default/main.cpp index 017d6495cd..6b47d0d4c4 100644 --- a/examples/qml/referenceexamples/default/main.cpp +++ b/examples/qml/referenceexamples/default/main.cpp @@ -58,11 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); - qmlRegisterType<Person>(); - qmlRegisterType<Boy>("People", 1,0, "Boy"); - qmlRegisterType<Girl>("People", 1,0, "Girl"); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); @@ -77,9 +72,10 @@ int main(int argc, char ** argv) for (int ii = 0; ii < party->guestCount(); ++ii) qWarning() << " " << party->guest(ii)->name(); - } else { - qWarning() << component.errors(); + + return EXIT_SUCCESS; } - return 0; + qWarning() << component.errors(); + return EXIT_FAILURE; } diff --git a/examples/qml/referenceexamples/default/person.h b/examples/qml/referenceexamples/default/person.h index 87f69276bf..361a89c599 100644 --- a/examples/qml/referenceexamples/default/person.h +++ b/examples/qml/referenceexamples/default/person.h @@ -51,12 +51,14 @@ #define PERSON_H #include <QObject> +#include <QtQml/qqml.h> class Person : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) + QML_ANONYMOUS public: Person(QObject *parent = nullptr); @@ -73,6 +75,7 @@ private: class Boy : public Person { Q_OBJECT + QML_ELEMENT public: Boy(QObject * parent = nullptr); }; @@ -80,6 +83,7 @@ public: class Girl : public Person { Q_OBJECT + QML_ELEMENT public: Girl(QObject * parent = nullptr); }; diff --git a/examples/qml/referenceexamples/extended/extended.pro b/examples/qml/referenceexamples/extended/extended.pro index 22d8ded708..094e5201ca 100644 --- a/examples/qml/referenceexamples/extended/extended.pro +++ b/examples/qml/referenceexamples/extended/extended.pro @@ -1,5 +1,9 @@ QT += qml widgets +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ lineedit.cpp HEADERS += lineedit.h diff --git a/examples/qml/referenceexamples/extended/lineedit.h b/examples/qml/referenceexamples/extended/lineedit.h index e8f7d90853..5c315ad5ac 100644 --- a/examples/qml/referenceexamples/extended/lineedit.h +++ b/examples/qml/referenceexamples/extended/lineedit.h @@ -51,6 +51,7 @@ #define LINEEDIT_H #include <QLineEdit> +#include <qqml.h> class LineEditExtension : public QObject { @@ -80,4 +81,14 @@ private: QLineEdit *m_lineedit; }; +// ![0] +struct QLineEditForeign +{ + Q_GADGET + QML_FOREIGN(QLineEdit) + QML_ELEMENT + QML_EXTENDED(LineEditExtension) +}; +// ![0] + #endif // LINEEDIT_H diff --git a/examples/qml/referenceexamples/extended/main.cpp b/examples/qml/referenceexamples/extended/main.cpp index f91cec76b1..26048d9189 100644 --- a/examples/qml/referenceexamples/extended/main.cpp +++ b/examples/qml/referenceexamples/extended/main.cpp @@ -58,10 +58,6 @@ int main(int argc, char ** argv) { QApplication app(argc, argv); -// ![0] - qmlRegisterExtendedType<QLineEdit, LineEditExtension>("People", 1,0, "QLineEdit"); -// ![0] - // ![1] QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); @@ -70,9 +66,9 @@ int main(int argc, char ** argv) if (edit) { edit->show(); - return app.exec(); - } else { - qWarning() << component.errors(); - return 0; + return QApplication::exec(); } + + qWarning() << component.errors(); + return EXIT_FAILURE; } diff --git a/examples/qml/referenceexamples/grouped/birthdayparty.cpp b/examples/qml/referenceexamples/grouped/birthdayparty.cpp index 1bae55076c..81db8ab1b8 100644 --- a/examples/qml/referenceexamples/grouped/birthdayparty.cpp +++ b/examples/qml/referenceexamples/grouped/birthdayparty.cpp @@ -66,7 +66,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty<Person> BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/grouped/birthdayparty.h b/examples/qml/referenceexamples/grouped/birthdayparty.h index edaa11fa88..f6834dad89 100644 --- a/examples/qml/referenceexamples/grouped/birthdayparty.h +++ b/examples/qml/referenceexamples/grouped/birthdayparty.h @@ -60,6 +60,7 @@ class BirthdayParty : public QObject Q_PROPERTY(Person *host READ host WRITE setHost) Q_PROPERTY(QQmlListProperty<Person> guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") + QML_ELEMENT public: BirthdayParty(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/grouped/grouped.pro b/examples/qml/referenceexamples/grouped/grouped.pro index ef66ea3e1d..1513ac552d 100644 --- a/examples/qml/referenceexamples/grouped/grouped.pro +++ b/examples/qml/referenceexamples/grouped/grouped.pro @@ -1,5 +1,9 @@ QT += qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp diff --git a/examples/qml/referenceexamples/grouped/main.cpp b/examples/qml/referenceexamples/grouped/main.cpp index 14cd64fe68..63dbe988a4 100644 --- a/examples/qml/referenceexamples/grouped/main.cpp +++ b/examples/qml/referenceexamples/grouped/main.cpp @@ -58,12 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); - qmlRegisterType<ShoeDescription>(); - qmlRegisterType<Person>(); - qmlRegisterType<Boy>("People", 1,0, "Boy"); - qmlRegisterType<Girl>("People", 1,0, "Girl"); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); @@ -87,9 +81,9 @@ int main(int argc, char ** argv) if (bestShoe) qWarning() << bestShoe->name() << "is wearing the best shoes!"; - } else { - qWarning() << component.errors(); + return EXIT_SUCCESS; } - return 0; + qWarning() << component.errors(); + return EXIT_FAILURE; } diff --git a/examples/qml/referenceexamples/grouped/person.h b/examples/qml/referenceexamples/grouped/person.h index 6f6caaee7c..df507c7386 100644 --- a/examples/qml/referenceexamples/grouped/person.h +++ b/examples/qml/referenceexamples/grouped/person.h @@ -52,6 +52,7 @@ #include <QObject> #include <QColor> +#include <QtQml/qqml.h> class ShoeDescription : public QObject { @@ -60,6 +61,7 @@ class ShoeDescription : public QObject Q_PROPERTY(QColor color READ color WRITE setColor) Q_PROPERTY(QString brand READ brand WRITE setBrand) Q_PROPERTY(qreal price READ price WRITE setPrice) + QML_ANONYMOUS public: ShoeDescription(QObject *parent = nullptr); @@ -88,6 +90,7 @@ class Person : public QObject // ![1] Q_PROPERTY(ShoeDescription *shoe READ shoe) // ![1] + QML_ANONYMOUS public: Person(QObject *parent = nullptr); @@ -103,6 +106,7 @@ private: class Boy : public Person { Q_OBJECT + QML_ELEMENT public: Boy(QObject * parent = nullptr); }; @@ -110,6 +114,7 @@ public: class Girl : public Person { Q_OBJECT + QML_ELEMENT public: Girl(QObject * parent = nullptr); }; diff --git a/examples/qml/referenceexamples/methods/birthdayparty.cpp b/examples/qml/referenceexamples/methods/birthdayparty.cpp index 7e750e4f4b..4b30d31aeb 100644 --- a/examples/qml/referenceexamples/methods/birthdayparty.cpp +++ b/examples/qml/referenceexamples/methods/birthdayparty.cpp @@ -67,7 +67,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty<Person> BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/methods/birthdayparty.h b/examples/qml/referenceexamples/methods/birthdayparty.h index 0eb968a841..5c2f3c9def 100644 --- a/examples/qml/referenceexamples/methods/birthdayparty.h +++ b/examples/qml/referenceexamples/methods/birthdayparty.h @@ -59,6 +59,7 @@ class BirthdayParty : public QObject Q_OBJECT Q_PROPERTY(Person *host READ host WRITE setHost) Q_PROPERTY(QQmlListProperty<Person> guests READ guests) + QML_ELEMENT public: BirthdayParty(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/methods/main.cpp b/examples/qml/referenceexamples/methods/main.cpp index 89404ec822..e30e1d9fb1 100644 --- a/examples/qml/referenceexamples/methods/main.cpp +++ b/examples/qml/referenceexamples/methods/main.cpp @@ -58,9 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); - qmlRegisterType<Person>("People", 1,0, "Person"); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); @@ -70,9 +67,9 @@ int main(int argc, char ** argv) qWarning() << "They are inviting:"; for (int ii = 0; ii < party->guestCount(); ++ii) qWarning() << " " << party->guest(ii)->name(); - } else { - qWarning() << component.errors(); + return EXIT_SUCCESS; } - return 0; + qWarning() << component.errors(); + return EXIT_FAILURE; } diff --git a/examples/qml/referenceexamples/methods/methods.pro b/examples/qml/referenceexamples/methods/methods.pro index 008ba19d96..2a5f3cff41 100644 --- a/examples/qml/referenceexamples/methods/methods.pro +++ b/examples/qml/referenceexamples/methods/methods.pro @@ -1,5 +1,9 @@ QT = core qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp diff --git a/examples/qml/referenceexamples/methods/person.h b/examples/qml/referenceexamples/methods/person.h index 749109dc72..2407fbb1b9 100644 --- a/examples/qml/referenceexamples/methods/person.h +++ b/examples/qml/referenceexamples/methods/person.h @@ -51,12 +51,14 @@ #define PERSON_H #include <QObject> +#include <QtQml/qqml.h> class Person : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) + QML_ELEMENT public: Person(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/properties/birthdayparty.cpp b/examples/qml/referenceexamples/properties/birthdayparty.cpp index 9abb08dbd9..fe6abab3f5 100644 --- a/examples/qml/referenceexamples/properties/birthdayparty.cpp +++ b/examples/qml/referenceexamples/properties/birthdayparty.cpp @@ -71,7 +71,9 @@ QQmlListProperty<Person> BirthdayParty::guests() &BirthdayParty::appendGuest, &BirthdayParty::guestCount, &BirthdayParty::guest, - &BirthdayParty::clearGuests}; + &BirthdayParty::clearGuests, + &BirthdayParty::replaceGuest, + &BirthdayParty::removeLastGuest}; } void BirthdayParty::appendGuest(Person* p) { @@ -93,6 +95,16 @@ void BirthdayParty::clearGuests() { m_guests.clear(); } +void BirthdayParty::replaceGuest(int index, Person *p) +{ + m_guests[index] = p; +} + +void BirthdayParty::removeLastGuest() +{ + m_guests.removeLast(); +} + // ![0] void BirthdayParty::appendGuest(QQmlListProperty<Person>* list, Person* p) { @@ -103,6 +115,16 @@ void BirthdayParty::clearGuests(QQmlListProperty<Person>* list) { reinterpret_cast< BirthdayParty* >(list->data)->clearGuests(); } +void BirthdayParty::replaceGuest(QQmlListProperty<Person> *list, int i, Person *p) +{ + reinterpret_cast< BirthdayParty* >(list->data)->replaceGuest(i, p); +} + +void BirthdayParty::removeLastGuest(QQmlListProperty<Person> *list) +{ + reinterpret_cast< BirthdayParty* >(list->data)->removeLastGuest(); +} + Person* BirthdayParty::guest(QQmlListProperty<Person>* list, int i) { return reinterpret_cast< BirthdayParty* >(list->data)->guest(i); } diff --git a/examples/qml/referenceexamples/properties/birthdayparty.h b/examples/qml/referenceexamples/properties/birthdayparty.h index 8d62c8dcd5..a5704972cc 100644 --- a/examples/qml/referenceexamples/properties/birthdayparty.h +++ b/examples/qml/referenceexamples/properties/birthdayparty.h @@ -67,6 +67,7 @@ class BirthdayParty : public QObject Q_PROPERTY(QQmlListProperty<Person> guests READ guests) // ![2] // ![3] + QML_ELEMENT public: BirthdayParty(QObject *parent = nullptr); @@ -78,12 +79,16 @@ public: int guestCount() const; Person *guest(int) const; void clearGuests(); + void replaceGuest(int, Person*); + void removeLastGuest(); private: static void appendGuest(QQmlListProperty<Person>*, Person*); static int guestCount(QQmlListProperty<Person>*); static Person* guest(QQmlListProperty<Person>*, int); static void clearGuests(QQmlListProperty<Person>*); + static void replaceGuest(QQmlListProperty<Person>*, int, Person*); + static void removeLastGuest(QQmlListProperty<Person>*); Person *m_host; QVector<Person *> m_guests; diff --git a/examples/qml/referenceexamples/properties/main.cpp b/examples/qml/referenceexamples/properties/main.cpp index a0a2335034..e30e1d9fb1 100644 --- a/examples/qml/referenceexamples/properties/main.cpp +++ b/examples/qml/referenceexamples/properties/main.cpp @@ -58,11 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); -//![register list] - qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); - qmlRegisterType<Person>("People", 1,0, "Person"); -//![register list] - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); @@ -72,9 +67,9 @@ int main(int argc, char ** argv) qWarning() << "They are inviting:"; for (int ii = 0; ii < party->guestCount(); ++ii) qWarning() << " " << party->guest(ii)->name(); - } else { - qWarning() << component.errors(); + return EXIT_SUCCESS; } - return 0; + qWarning() << component.errors(); + return EXIT_FAILURE; } diff --git a/examples/qml/referenceexamples/properties/person.h b/examples/qml/referenceexamples/properties/person.h index 749109dc72..2407fbb1b9 100644 --- a/examples/qml/referenceexamples/properties/person.h +++ b/examples/qml/referenceexamples/properties/person.h @@ -51,12 +51,14 @@ #define PERSON_H #include <QObject> +#include <QtQml/qqml.h> class Person : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) + QML_ELEMENT public: Person(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/properties/properties.pro b/examples/qml/referenceexamples/properties/properties.pro index 101c878abd..6697afa2c5 100644 --- a/examples/qml/referenceexamples/properties/properties.pro +++ b/examples/qml/referenceexamples/properties/properties.pro @@ -1,5 +1,9 @@ QT = core qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp diff --git a/examples/qml/referenceexamples/signal/birthdayparty.cpp b/examples/qml/referenceexamples/signal/birthdayparty.cpp index 9d34cdf146..405c8af940 100644 --- a/examples/qml/referenceexamples/signal/birthdayparty.cpp +++ b/examples/qml/referenceexamples/signal/birthdayparty.cpp @@ -82,7 +82,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty<Person> BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/signal/birthdayparty.h b/examples/qml/referenceexamples/signal/birthdayparty.h index 9aecc8929c..c815518291 100644 --- a/examples/qml/referenceexamples/signal/birthdayparty.h +++ b/examples/qml/referenceexamples/signal/birthdayparty.h @@ -59,6 +59,7 @@ class BirthdayPartyAttached : public QObject { Q_OBJECT Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) + QML_ANONYMOUS public: BirthdayPartyAttached(QObject *object); @@ -75,6 +76,8 @@ class BirthdayParty : public QObject Q_PROPERTY(Person *host READ host WRITE setHost) Q_PROPERTY(QQmlListProperty<Person> guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") + QML_ELEMENT + QML_ATTACHED(BirthdayPartyAttached) public: BirthdayParty(QObject *parent = nullptr); @@ -97,6 +100,5 @@ private: Person *m_host; QList<Person *> m_guests; }; -QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) #endif // BIRTHDAYPARTY_H diff --git a/examples/qml/referenceexamples/signal/example.qml b/examples/qml/referenceexamples/signal/example.qml index 42d6c44939..5d80d58867 100644 --- a/examples/qml/referenceexamples/signal/example.qml +++ b/examples/qml/referenceexamples/signal/example.qml @@ -53,7 +53,7 @@ import QtQuick 2.0 // For QColor BirthdayParty { // ![0] - onPartyStarted: console.log("This party started rockin' at " + time); + onPartyStarted: (time) => { console.log("This party started rockin' at " + time); } // ![0] host: Boy { diff --git a/examples/qml/referenceexamples/signal/main.cpp b/examples/qml/referenceexamples/signal/main.cpp index bb75e02bc2..7ef3595a8c 100644 --- a/examples/qml/referenceexamples/signal/main.cpp +++ b/examples/qml/referenceexamples/signal/main.cpp @@ -58,13 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterType<BirthdayPartyAttached>(); - qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); - qmlRegisterType<ShoeDescription>(); - qmlRegisterType<Person>(); - qmlRegisterType<Boy>("People", 1,0, "Boy"); - qmlRegisterType<Girl>("People", 1,0, "Girl"); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); @@ -93,9 +86,9 @@ int main(int argc, char ** argv) } party->startParty(); - } else { - qWarning() << component.errors(); + return EXIT_SUCCESS; } - return 0; + qWarning() << component.errors(); + return EXIT_FAILURE; } diff --git a/examples/qml/referenceexamples/signal/person.h b/examples/qml/referenceexamples/signal/person.h index 06d4f2eb27..7283f39f61 100644 --- a/examples/qml/referenceexamples/signal/person.h +++ b/examples/qml/referenceexamples/signal/person.h @@ -52,6 +52,7 @@ #include <QObject> #include <QColor> +#include <QtQml/qqml.h> class ShoeDescription : public QObject { @@ -60,6 +61,7 @@ class ShoeDescription : public QObject Q_PROPERTY(QColor color READ color WRITE setColor) Q_PROPERTY(QString brand READ brand WRITE setBrand) Q_PROPERTY(qreal price READ price WRITE setPrice) + QML_ANONYMOUS public: ShoeDescription(QObject *parent = nullptr); @@ -86,6 +88,7 @@ class Person : public QObject Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(ShoeDescription *shoe READ shoe) + QML_ANONYMOUS public: Person(QObject *parent = nullptr); @@ -101,6 +104,7 @@ private: class Boy : public Person { Q_OBJECT + QML_ELEMENT public: Boy(QObject * parent = nullptr); }; @@ -108,6 +112,7 @@ public: class Girl : public Person { Q_OBJECT + QML_ELEMENT public: Girl(QObject * parent = nullptr); }; diff --git a/examples/qml/referenceexamples/signal/signal.pro b/examples/qml/referenceexamples/signal/signal.pro index 2dbc8e624b..3c31234b3c 100644 --- a/examples/qml/referenceexamples/signal/signal.pro +++ b/examples/qml/referenceexamples/signal/signal.pro @@ -1,5 +1,9 @@ QT += qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp diff --git a/examples/qml/referenceexamples/valuesource/birthdayparty.cpp b/examples/qml/referenceexamples/valuesource/birthdayparty.cpp index 68d5767e8d..6a5e67aa0d 100644 --- a/examples/qml/referenceexamples/valuesource/birthdayparty.cpp +++ b/examples/qml/referenceexamples/valuesource/birthdayparty.cpp @@ -82,7 +82,7 @@ void BirthdayParty::setHost(Person *c) QQmlListProperty<Person> BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const diff --git a/examples/qml/referenceexamples/valuesource/birthdayparty.h b/examples/qml/referenceexamples/valuesource/birthdayparty.h index 18a9b96147..25e2342937 100644 --- a/examples/qml/referenceexamples/valuesource/birthdayparty.h +++ b/examples/qml/referenceexamples/valuesource/birthdayparty.h @@ -60,6 +60,7 @@ class BirthdayPartyAttached : public QObject { Q_OBJECT Q_PROPERTY(QDate rsvp READ rsvp WRITE setRsvp) + QML_ANONYMOUS public: BirthdayPartyAttached(QObject *object); @@ -79,6 +80,8 @@ class BirthdayParty : public QObject Q_PROPERTY(QString announcement READ announcement WRITE setAnnouncement) // ![0] Q_CLASSINFO("DefaultProperty", "guests") + QML_ELEMENT + QML_ATTACHED(BirthdayPartyAttached) public: BirthdayParty(QObject *parent = nullptr); @@ -102,6 +105,5 @@ private: Person *m_host; QList<Person *> m_guests; }; -QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) #endif // BIRTHDAYPARTY_H diff --git a/examples/qml/referenceexamples/valuesource/example.qml b/examples/qml/referenceexamples/valuesource/example.qml index 0abb76261c..65d511058a 100644 --- a/examples/qml/referenceexamples/valuesource/example.qml +++ b/examples/qml/referenceexamples/valuesource/example.qml @@ -56,7 +56,7 @@ BirthdayParty { HappyBirthdaySong on announcement { name: "Bob Jones" } // ![0] - onPartyStarted: console.log("This party started rockin' at " + time); + onPartyStarted: (time) => { console.log("This party started rockin' at " + time); } host: Boy { diff --git a/examples/qml/referenceexamples/valuesource/happybirthdaysong.h b/examples/qml/referenceexamples/valuesource/happybirthdaysong.h index e2205a4ebb..2600208968 100644 --- a/examples/qml/referenceexamples/valuesource/happybirthdaysong.h +++ b/examples/qml/referenceexamples/valuesource/happybirthdaysong.h @@ -64,6 +64,7 @@ class HappyBirthdaySong : public QObject, public QQmlPropertyValueSource // ![0] Q_PROPERTY(QString name READ name WRITE setName) // ![1] + QML_ELEMENT public: HappyBirthdaySong(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/valuesource/main.cpp b/examples/qml/referenceexamples/valuesource/main.cpp index 4bef695fe2..2e9995fcd8 100644 --- a/examples/qml/referenceexamples/valuesource/main.cpp +++ b/examples/qml/referenceexamples/valuesource/main.cpp @@ -59,14 +59,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterType<BirthdayPartyAttached>(); - qmlRegisterType<BirthdayParty>("People", 1,0, "BirthdayParty"); - qmlRegisterType<HappyBirthdaySong>("People", 1,0, "HappyBirthdaySong"); - qmlRegisterType<ShoeDescription>(); - qmlRegisterType<Person>(); - qmlRegisterType<Boy>("People", 1,0, "Boy"); - qmlRegisterType<Girl>("People", 1,0, "Girl"); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast<BirthdayParty *>(component.create()); @@ -95,9 +87,9 @@ int main(int argc, char ** argv) } party->startParty(); - } else { - qWarning() << component.errors(); + return QCoreApplication::exec(); } - return app.exec(); + qWarning() << component.errors(); + return EXIT_FAILURE; } diff --git a/examples/qml/referenceexamples/valuesource/person.h b/examples/qml/referenceexamples/valuesource/person.h index 06d4f2eb27..7283f39f61 100644 --- a/examples/qml/referenceexamples/valuesource/person.h +++ b/examples/qml/referenceexamples/valuesource/person.h @@ -52,6 +52,7 @@ #include <QObject> #include <QColor> +#include <QtQml/qqml.h> class ShoeDescription : public QObject { @@ -60,6 +61,7 @@ class ShoeDescription : public QObject Q_PROPERTY(QColor color READ color WRITE setColor) Q_PROPERTY(QString brand READ brand WRITE setBrand) Q_PROPERTY(qreal price READ price WRITE setPrice) + QML_ANONYMOUS public: ShoeDescription(QObject *parent = nullptr); @@ -86,6 +88,7 @@ class Person : public QObject Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(ShoeDescription *shoe READ shoe) + QML_ANONYMOUS public: Person(QObject *parent = nullptr); @@ -101,6 +104,7 @@ private: class Boy : public Person { Q_OBJECT + QML_ELEMENT public: Boy(QObject * parent = nullptr); }; @@ -108,6 +112,7 @@ public: class Girl : public Person { Q_OBJECT + QML_ELEMENT public: Girl(QObject * parent = nullptr); }; diff --git a/examples/qml/referenceexamples/valuesource/valuesource.pro b/examples/qml/referenceexamples/valuesource/valuesource.pro index 01cfeeb6d8..6d29cf1b70 100644 --- a/examples/qml/referenceexamples/valuesource/valuesource.pro +++ b/examples/qml/referenceexamples/valuesource/valuesource.pro @@ -1,5 +1,9 @@ QT += qml +CONFIG += qmltypes +QML_IMPORT_NAME = People +QML_IMPORT_MAJOR_VERSION = 1 + SOURCES += main.cpp \ person.cpp \ birthdayparty.cpp \ diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.pro b/examples/qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.pro index 9911e02484..1f777d2ea8 100644 --- a/examples/qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.pro +++ b/examples/qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.pro @@ -1,5 +1,11 @@ QT += qml quick +#![0] +CONFIG += qmltypes +QML_IMPORT_NAME = Charts +QML_IMPORT_MAJOR_VERSION = 1 +#![0] + HEADERS += piechart.h SOURCES += piechart.cpp \ main.cpp diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp b/examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp index fbff60c0e6..10df9c2566 100644 --- a/examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp +++ b/examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp @@ -56,8 +56,6 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart"); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/piechart.h b/examples/qml/tutorials/extending-qml/chapter1-basics/piechart.h index 005a706db6..687f8e2b4d 100644 --- a/examples/qml/tutorials/extending-qml/chapter1-basics/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter1-basics/piechart.h @@ -59,6 +59,7 @@ class PieChart : public QQuickPaintedItem Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QColor color READ color WRITE setColor) + QML_ELEMENT public: PieChart(QQuickItem *parent = 0); diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/chapter2-methods.pro b/examples/qml/tutorials/extending-qml/chapter2-methods/chapter2-methods.pro index 7fd850ce36..264f028f5c 100644 --- a/examples/qml/tutorials/extending-qml/chapter2-methods/chapter2-methods.pro +++ b/examples/qml/tutorials/extending-qml/chapter2-methods/chapter2-methods.pro @@ -1,5 +1,9 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = Charts +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += piechart.h SOURCES += piechart.cpp \ main.cpp diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/main.cpp b/examples/qml/tutorials/extending-qml/chapter2-methods/main.cpp index fbff60c0e6..10df9c2566 100644 --- a/examples/qml/tutorials/extending-qml/chapter2-methods/main.cpp +++ b/examples/qml/tutorials/extending-qml/chapter2-methods/main.cpp @@ -56,8 +56,6 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart"); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/piechart.h b/examples/qml/tutorials/extending-qml/chapter2-methods/piechart.h index 36bfa3ada0..271afbf653 100644 --- a/examples/qml/tutorials/extending-qml/chapter2-methods/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter2-methods/piechart.h @@ -60,7 +60,7 @@ class PieChart : public QQuickPaintedItem Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QColor color READ color WRITE setColor) - + QML_ELEMENT //![1] public: //![1] diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/chapter3-bindings.pro b/examples/qml/tutorials/extending-qml/chapter3-bindings/chapter3-bindings.pro index 1ae83f71eb..152f17ce8c 100644 --- a/examples/qml/tutorials/extending-qml/chapter3-bindings/chapter3-bindings.pro +++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/chapter3-bindings.pro @@ -1,5 +1,9 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = Charts +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += piechart.h SOURCES += piechart.cpp \ main.cpp diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/main.cpp b/examples/qml/tutorials/extending-qml/chapter3-bindings/main.cpp index fbff60c0e6..10df9c2566 100644 --- a/examples/qml/tutorials/extending-qml/chapter3-bindings/main.cpp +++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/main.cpp @@ -56,8 +56,6 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart"); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/piechart.h b/examples/qml/tutorials/extending-qml/chapter3-bindings/piechart.h index 9de2baa82e..58b1339298 100644 --- a/examples/qml/tutorials/extending-qml/chapter3-bindings/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/piechart.h @@ -59,6 +59,7 @@ class PieChart : public QQuickPaintedItem //![0] Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) + QML_ELEMENT //![1] Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro index 12dfbd6280..e277f74676 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/chapter4-customPropertyTypes.pro @@ -1,5 +1,9 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = Charts +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += piechart.h \ pieslice.h SOURCES += piechart.cpp \ diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp index 82355d0438..76e075a72c 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp @@ -59,12 +59,6 @@ int main(int argc, char *argv[]) //![0] QGuiApplication app(argc, argv); - qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart"); - -//![1] - qmlRegisterType<PieSlice>("Charts", 1, 0, "PieSlice"); -//![1] - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h index 6cd09a9293..b762ce1c49 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h @@ -61,7 +61,7 @@ class PieChart : public QQuickItem Q_PROPERTY(PieSlice* pieSlice READ pieSlice WRITE setPieSlice) //![0] Q_PROPERTY(QString name READ name WRITE setName) - + QML_ELEMENT //![1] public: //![1] diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/pieslice.h b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/pieslice.h index 10ab4d34b6..6e64917851 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/pieslice.h +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/pieslice.h @@ -58,6 +58,7 @@ class PieSlice : public QQuickPaintedItem { Q_OBJECT Q_PROPERTY(QColor color READ color WRITE setColor) + QML_ELEMENT public: PieSlice(QQuickItem *parent = 0); diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/chapter5-listproperties.pro b/examples/qml/tutorials/extending-qml/chapter5-listproperties/chapter5-listproperties.pro index 67d1cd35c3..edbd3c237d 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/chapter5-listproperties.pro +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/chapter5-listproperties.pro @@ -1,5 +1,9 @@ QT += qml quick +CONFIG += qmltypes +QML_IMPORT_NAME = Charts +QML_IMPORT_MAJOR_VERSION = 1 + HEADERS += piechart.h \ pieslice.h SOURCES += piechart.cpp \ diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp b/examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp index 8aa6fef018..7262969b62 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp @@ -57,9 +57,6 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterType<PieChart>("Charts", 1, 0, "PieChart"); - qmlRegisterType<PieSlice>("Charts", 1, 0, "PieSlice"); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.cpp b/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.cpp index ac680bb9c9..a8e14db542 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.cpp +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.cpp @@ -68,7 +68,8 @@ void PieChart::setName(const QString &name) //![0] QQmlListProperty<PieSlice> PieChart::slices() { - return QQmlListProperty<PieSlice>(this, nullptr, &PieChart::append_slice, nullptr, nullptr, nullptr); + return QQmlListProperty<PieSlice>(this, nullptr, &PieChart::append_slice, nullptr, + nullptr, nullptr, nullptr, nullptr); } void PieChart::append_slice(QQmlListProperty<PieSlice> *list, PieSlice *slice) diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.h b/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.h index 9b3390b902..236fa6796f 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/piechart.h @@ -61,6 +61,7 @@ class PieChart : public QQuickItem Q_PROPERTY(QQmlListProperty<PieSlice> slices READ slices) //![0] Q_PROPERTY(QString name READ name WRITE setName) + QML_ELEMENT //![1] public: diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.h b/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.h index f8f7f7c36a..0b290851f0 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.h +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/pieslice.h @@ -60,6 +60,7 @@ class PieSlice : public QQuickPaintedItem Q_PROPERTY(QColor color READ color WRITE setColor) Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle) Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan) + QML_ELEMENT //![0] public: diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h index 69a858d48b..780bb3a8f3 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h @@ -51,15 +51,12 @@ #define CHARTSPLUGIN_H //![0] -#include <QQmlExtensionPlugin> +#include <QQmlEngineExtensionPlugin> -class ChartsPlugin : public QQmlExtensionPlugin +class ChartsPlugin : public QQmlEngineExtensionPlugin { Q_OBJECT - Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) - -public: - void registerTypes(const char *uri); + Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) }; //![0] diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro index 5cf4621420..c37cd1fdee 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro @@ -1,8 +1,11 @@ TEMPLATE = lib -CONFIG += plugin +CONFIG += plugin qmltypes QT += qml quick -DESTDIR = ../Charts +QML_IMPORT_NAME = Charts +QML_IMPORT_MAJOR_VERSION = 1 + +DESTDIR = ../$$QML_IMPORT_NAME TARGET = $$qtLibraryTarget(chartsplugin) HEADERS += piechart.h \ @@ -10,10 +13,13 @@ HEADERS += piechart.h \ chartsplugin.h SOURCES += piechart.cpp \ - pieslice.cpp \ - chartsplugin.cpp + pieslice.cpp + +DESTPATH=$$[QT_INSTALL_EXAMPLES]/qml/tutorials/extending-qml/chapter6-plugins/$$QML_IMPORT_NAME -DESTPATH=$$[QT_INSTALL_EXAMPLES]/qml/tutorials/extending-qml/chapter6-plugins/Charts +copy_qmltypes.files = $$OUT_PWD/plugins.qmltypes +copy_qmltypes.path = $$DESTDIR +COPIES += copy_qmltypes target.path=$$DESTPATH qmldir.files=$$PWD/qmldir diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.cpp b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.cpp index 1c712c887a..536c0e16ae 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.cpp +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.cpp @@ -67,7 +67,8 @@ void PieChart::setName(const QString &name) QQmlListProperty<PieSlice> PieChart::slices() { - return QQmlListProperty<PieSlice>(this, nullptr, &PieChart::append_slice, nullptr, nullptr, nullptr); + return QQmlListProperty<PieSlice>(this, nullptr, &PieChart::append_slice, nullptr, + nullptr, nullptr, nullptr, nullptr); } void PieChart::append_slice(QQmlListProperty<PieSlice> *list, PieSlice *slice) diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.h index cd67bdf34a..e6b768b274 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.h @@ -59,6 +59,7 @@ class PieChart : public QQuickItem Q_OBJECT Q_PROPERTY(QQmlListProperty<PieSlice> slices READ slices) Q_PROPERTY(QString name READ name WRITE setName) + QML_ELEMENT public: PieChart(QQuickItem *parent = 0); diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.h index 71cc20a369..091870bd51 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.h +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.h @@ -59,6 +59,7 @@ class PieSlice : public QQuickPaintedItem Q_PROPERTY(QColor color READ color WRITE setColor) Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle) Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan) + QML_ELEMENT public: PieSlice(QQuickItem *parent = 0); diff --git a/examples/qml/xmlhttprequest/Get.qml b/examples/qml/xmlhttprequest/Get.qml index 1a35d32666..96cec2a99d 100644 --- a/examples/qml/xmlhttprequest/Get.qml +++ b/examples/qml/xmlhttprequest/Get.qml @@ -58,7 +58,7 @@ GetForm mouseArea.onClicked: Utils.makeRequest() - button.border.width: button.pressed ? 2 : 1 + button.border.width: mouseArea.pressed ? 2 : 1 text.text: "Request data.xml" } |