From 4eff7299501ff932071300b3fa34fbeccb03d0d8 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Mon, 13 Jan 2020 12:49:05 +0100 Subject: Binding example: Fix type registration Fixes: QTBUG-81335 Change-Id: Ie93c9b7ad49703bce245592e659ccdb6ea2b7ed9 Reviewed-by: Ulf Hermann --- examples/qml/referenceexamples/binding/happybirthdaysong.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'examples/qml') diff --git a/examples/qml/referenceexamples/binding/happybirthdaysong.h b/examples/qml/referenceexamples/binding/happybirthdaysong.h index dcfebc06ba..a1582f0d4b 100644 --- a/examples/qml/referenceexamples/binding/happybirthdaysong.h +++ b/examples/qml/referenceexamples/binding/happybirthdaysong.h @@ -52,6 +52,7 @@ #include #include +#include #include @@ -60,6 +61,7 @@ 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); -- cgit v1.2.3 From 2c3419e127e55810da1741725b4ff39f118cd577 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 12 Sep 2019 17:03:52 +0200 Subject: Generate registrations for all examples Now that we can generate all QML type information at build time, we should also use it. Change-Id: I647c72bbe38fdb2deb565b75c86a696af3d15b61 Reviewed-by: Simon Hausmann --- examples/qml/doc/src/qml-extending.qdoc | 15 ++- examples/qml/qmlextensionplugins/plugin.cpp | 108 +------------------- .../qmlextensionplugins/qmlextensionplugins.pro | 36 ++++--- examples/qml/qmlextensionplugins/timemodel.cpp | 98 ++++++++++++++++++ examples/qml/qmlextensionplugins/timemodel.h | 111 +++++++++++++++++++++ examples/qml/referenceexamples/adding/adding.pro | 4 + examples/qml/referenceexamples/adding/main.cpp | 3 - .../qml/referenceexamples/attached/attached.pro | 4 + examples/qml/referenceexamples/attached/main.cpp | 4 - examples/qml/referenceexamples/binding/binding.pro | 4 + .../referenceexamples/binding/happybirthdaysong.h | 1 + examples/qml/referenceexamples/binding/main.cpp | 2 - .../qml/referenceexamples/coercion/birthdayparty.h | 1 + .../qml/referenceexamples/coercion/coercion.pro | 4 + examples/qml/referenceexamples/coercion/main.cpp | 4 - examples/qml/referenceexamples/coercion/person.h | 3 +- .../qml/referenceexamples/default/birthdayparty.h | 1 + examples/qml/referenceexamples/default/default.pro | 4 + examples/qml/referenceexamples/default/main.cpp | 2 - .../qml/referenceexamples/extended/extended.pro | 4 + examples/qml/referenceexamples/extended/lineedit.h | 11 ++ examples/qml/referenceexamples/extended/main.cpp | 4 - .../qml/referenceexamples/grouped/birthdayparty.h | 1 + examples/qml/referenceexamples/grouped/grouped.pro | 4 + examples/qml/referenceexamples/grouped/main.cpp | 2 - .../qml/referenceexamples/methods/birthdayparty.h | 1 + examples/qml/referenceexamples/methods/main.cpp | 2 - examples/qml/referenceexamples/methods/methods.pro | 4 + .../referenceexamples/properties/birthdayparty.h | 1 + examples/qml/referenceexamples/properties/main.cpp | 4 - .../referenceexamples/properties/properties.pro | 4 + examples/qml/referenceexamples/signal/main.cpp | 3 - examples/qml/referenceexamples/signal/signal.pro | 4 + .../valuesource/happybirthdaysong.h | 1 + .../qml/referenceexamples/valuesource/main.cpp | 3 - .../referenceexamples/valuesource/valuesource.pro | 4 + .../chapter1-basics/chapter1-basics.pro | 4 + .../extending-qml/chapter1-basics/main.cpp | 2 - .../chapter2-methods/chapter2-methods.pro | 4 + .../extending-qml/chapter2-methods/main.cpp | 2 - .../chapter3-bindings/chapter3-bindings.pro | 4 + .../extending-qml/chapter3-bindings/main.cpp | 2 - .../chapter4-customPropertyTypes.pro | 4 + .../chapter4-customPropertyTypes/main.cpp | 4 - .../chapter5-listproperties.pro | 4 + .../extending-qml/chapter5-listproperties/main.cpp | 2 - .../chapter6-plugins/import/chartsplugin.cpp | 62 ------------ .../chapter6-plugins/import/chartsplugin.h | 7 +- .../chapter6-plugins/import/import.pro | 16 ++- 49 files changed, 338 insertions(+), 245 deletions(-) create mode 100644 examples/qml/qmlextensionplugins/timemodel.cpp create mode 100644 examples/qml/qmlextensionplugins/timemodel.h delete mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.cpp (limited to 'examples/qml') diff --git a/examples/qml/doc/src/qml-extending.qdoc b/examples/qml/doc/src/qml-extending.qdoc index 64d7235031..1ad3ae9a10 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 @@ -77,9 +73,11 @@ Shows how to use \l {QQmlEngine::}{qmlRegisterExtendedType()} 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: @@ -182,9 +180,8 @@ directly - an explicit Boy or Girl should be instantiated instead. 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. - -\snippet referenceexamples/coercion/main.cpp 0 +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/qmlextensionplugins/plugin.cpp b/examples/qml/qmlextensionplugins/plugin.cpp index a6d1d3ff63..99d8c5378c 100644 --- a/examples/qml/qmlextensionplugins/plugin.cpp +++ b/examples/qml/qmlextensionplugins/plugin.cpp @@ -49,117 +49,13 @@ ****************************************************************************/ #include -#include #include -#include -#include -#include - -// 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) - QML_NAMED_ELEMENT(Time) -//![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")); - qmlRegisterTypesAndRevisions(uri, 1); - } + Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) }; //![plugin] diff --git a/examples/qml/qmlextensionplugins/qmlextensionplugins.pro b/examples/qml/qmlextensionplugins/qmlextensionplugins.pro index 946626cce7..40c2b396a3 100644 --- a/examples/qml/qmlextensionplugins/qmlextensionplugins.pro +++ b/examples/qml/qmlextensionplugins/qmlextensionplugins.pro @@ -1,25 +1,37 @@ 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 -SOURCES += plugin.cpp +SOURCES += \ + plugin.cpp \ + timemodel.cpp + +HEADERS += \ + timemodel.h -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 +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 + +pluginfiles.files += $$PLUGINFILES 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 +target.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME +pluginfiles.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME 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 +#include +#include +#include + +// 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 ffd0e90c42..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] - qmlRegisterTypesAndRevisions("People", 1); -//![0] QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); 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/main.cpp b/examples/qml/referenceexamples/attached/main.cpp index ab1c6b9637..2fceb98ac9 100644 --- a/examples/qml/referenceexamples/attached/main.cpp +++ b/examples/qml/referenceexamples/attached/main.cpp @@ -58,10 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterTypesAndRevisions("People", 1); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast(component.create()); 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/happybirthdaysong.h b/examples/qml/referenceexamples/binding/happybirthdaysong.h index a1582f0d4b..c84e9d9e5e 100644 --- a/examples/qml/referenceexamples/binding/happybirthdaysong.h +++ b/examples/qml/referenceexamples/binding/happybirthdaysong.h @@ -55,6 +55,7 @@ #include #include +#include class HappyBirthdaySong : public QObject, public QQmlPropertyValueSource { diff --git a/examples/qml/referenceexamples/binding/main.cpp b/examples/qml/referenceexamples/binding/main.cpp index 8c6e3222d8..2e9995fcd8 100644 --- a/examples/qml/referenceexamples/binding/main.cpp +++ b/examples/qml/referenceexamples/binding/main.cpp @@ -58,8 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterTypesAndRevisions("People", 1); QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); 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 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 2c2bd92e8d..6b47d0d4c4 100644 --- a/examples/qml/referenceexamples/coercion/main.cpp +++ b/examples/qml/referenceexamples/coercion/main.cpp @@ -58,10 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - //![0] - qmlRegisterTypesAndRevisions("People", 1); - //![0] - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast(component.create()); diff --git a/examples/qml/referenceexamples/coercion/person.h b/examples/qml/referenceexamples/coercion/person.h index 6865e0093a..7e2828da04 100644 --- a/examples/qml/referenceexamples/coercion/person.h +++ b/examples/qml/referenceexamples/coercion/person.h @@ -59,7 +59,8 @@ class Person : public QObject Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(int shoeSize READ shoeSize WRITE setShoeSize) //![0] - QML_ANONYMOUS + QML_ELEMENT + QML_UNCREATABLE("Person is an abstract base class.") //![0] public: Person(QObject *parent = nullptr); 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 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 bbe4a239e2..6b47d0d4c4 100644 --- a/examples/qml/referenceexamples/default/main.cpp +++ b/examples/qml/referenceexamples/default/main.cpp @@ -58,8 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterTypesAndRevisions("People", 1); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast(component.create()); 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 +#include 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 5f8582d08f..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("People", 1,0, "QLineEdit"); -// ![0] - // ![1] QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); 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 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 e233aab5b1..63dbe988a4 100644 --- a/examples/qml/referenceexamples/grouped/main.cpp +++ b/examples/qml/referenceexamples/grouped/main.cpp @@ -58,8 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterTypesAndRevisions("People", 1); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast(component.create()); 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 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 4dd616f8cd..e30e1d9fb1 100644 --- a/examples/qml/referenceexamples/methods/main.cpp +++ b/examples/qml/referenceexamples/methods/main.cpp @@ -58,8 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterTypesAndRevisions("People", 1); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast(component.create()); 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/properties/birthdayparty.h b/examples/qml/referenceexamples/properties/birthdayparty.h index 8d62c8dcd5..fb8b63a79d 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 guests READ guests) // ![2] // ![3] + QML_ELEMENT public: BirthdayParty(QObject *parent = nullptr); diff --git a/examples/qml/referenceexamples/properties/main.cpp b/examples/qml/referenceexamples/properties/main.cpp index 216869bf6c..e30e1d9fb1 100644 --- a/examples/qml/referenceexamples/properties/main.cpp +++ b/examples/qml/referenceexamples/properties/main.cpp @@ -58,10 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); -//![register list] - qmlRegisterTypesAndRevisions("People", 1); -//![register list] - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast(component.create()); 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/main.cpp b/examples/qml/referenceexamples/signal/main.cpp index f431e2bdc8..7ef3595a8c 100644 --- a/examples/qml/referenceexamples/signal/main.cpp +++ b/examples/qml/referenceexamples/signal/main.cpp @@ -58,9 +58,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterTypesAndRevisions("People", 1); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast(component.create()); 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/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 72e75fdea1..2e9995fcd8 100644 --- a/examples/qml/referenceexamples/valuesource/main.cpp +++ b/examples/qml/referenceexamples/valuesource/main.cpp @@ -59,9 +59,6 @@ int main(int argc, char ** argv) { QCoreApplication app(argc, argv); - qmlRegisterTypesAndRevisions("People", 1); - QQmlEngine engine; QQmlComponent component(&engine, QUrl("qrc:example.qml")); auto *party = qobject_cast(component.create()); 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..294a9ad0e8 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,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/chapter1-basics/main.cpp b/examples/qml/tutorials/extending-qml/chapter1-basics/main.cpp index af50cc14f2..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); - qmlRegisterTypesAndRevisions("Charts", 1); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); 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 af50cc14f2..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); - qmlRegisterTypesAndRevisions("Charts", 1); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); 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 af50cc14f2..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); - qmlRegisterTypesAndRevisions("Charts", 1); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); 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 7c5d1a6885..76e075a72c 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/main.cpp @@ -59,10 +59,6 @@ int main(int argc, char *argv[]) //![0] QGuiApplication app(argc, argv); -//![1] - qmlRegisterTypesAndRevisions("Charts", 1); -//![1] - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); 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 70ef103e4d..7262969b62 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/main.cpp @@ -57,8 +57,6 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - qmlRegisterTypesAndRevisions("Charts", 1); - QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QUrl("qrc:///app.qml")); diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.cpp b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.cpp deleted file mode 100644 index 74d382ec57..0000000000 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation 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 "chartsplugin.h" -//![0] -#include "piechart.h" -#include "pieslice.h" -#include - -void ChartsPlugin::registerTypes(const char *uri) -{ - qmlRegisterTypesAndRevisions(uri, 1); -} - -//![0] - 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..0b1cfcc8f1 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h @@ -53,13 +53,10 @@ //![0] #include -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 -- cgit v1.2.3 From da4cdfec983572148bd41dbacaacb318783e519c Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 15 Nov 2019 12:23:49 +0100 Subject: examples: Make qmlextensionplugins example usable without installation The qmldir file as well as the .qml files have to be placed next to the plugin, the import path has to be added to the .qmlproject, we want the .qmltypes file added to the same place, and the plugins.qml should also be available in the destination directory. Change-Id: I82b369693e612779c6213345cc8f6a30b16d41b4 Reviewed-by: Simon Hausmann --- examples/qml/qmlextensionplugins/plugins.qmlproject | 2 ++ .../qml/qmlextensionplugins/qmlextensionplugins.pro | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'examples/qml') 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 40c2b396a3..c074b8d671 100644 --- a/examples/qml/qmlextensionplugins/qmlextensionplugins.pro +++ b/examples/qml/qmlextensionplugins/qmlextensionplugins.pro @@ -7,6 +7,7 @@ QML_IMPORT_MAJOR_VERSION = 1 DESTDIR = imports/$$QML_IMPORT_NAME TARGET = qmlqtimeexampleplugin +QMLTYPES_FILENAME = $$DESTDIR/plugins.qmltypes SOURCES += \ plugin.cpp \ @@ -23,14 +24,22 @@ PLUGINFILES = \ imports/$$QML_IMPORT_NAME/hour.png \ imports/$$QML_IMPORT_NAME/minute.png -pluginfiles.files += $$PLUGINFILES +target.path = $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME -qml.files = plugins.qml -qml.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins -target.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME -pluginfiles.path += $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME +pluginfiles_copy.files = $$PLUGINFILES +pluginfiles_copy.path = $$DESTDIR -INSTALLS += target qml pluginfiles +pluginfiles_install.files = $$PLUGINFILES $$OUT_PWD/$$DESTDIR/plugins.qmltypes +pluginfiles_install.path = $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins/imports/$$QML_IMPORT_NAME + +qml_copy.files = plugins.qml plugins.qmlproject +qml_copy.path = $$OUT_PWD + +qml_install.files = plugins.qml plugins.qmlproject +qml_install.path = $$[QT_INSTALL_EXAMPLES]/qml/qmlextensionplugins + +INSTALLS += target qml_install pluginfiles_install +COPIES += qml_copy pluginfiles_copy OTHER_FILES += $$PLUGINFILES plugins.qml -- cgit v1.2.3