From 6d0a453f41d304239285d64b06612c36922be701 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 25 Nov 2019 16:10:04 +0100 Subject: Use the extended QQmlListProperty interface in a few places Task-number: QTBUG-79263 Change-Id: If518f644b5b9eddbacfb1cb16fbb557127ffcfb2 Reviewed-by: Simon Hausmann Reviewed-by: Shawn Rutledge --- .../referenceexamples/attached/birthdayparty.cpp | 2 +- .../referenceexamples/binding/birthdayparty.cpp | 2 +- .../referenceexamples/coercion/birthdayparty.cpp | 2 +- .../referenceexamples/default/birthdayparty.cpp | 2 +- .../referenceexamples/grouped/birthdayparty.cpp | 2 +- .../referenceexamples/methods/birthdayparty.cpp | 2 +- .../referenceexamples/properties/birthdayparty.cpp | 24 +++++++++++++++++++++- .../referenceexamples/properties/birthdayparty.h | 4 ++++ .../qml/referenceexamples/signal/birthdayparty.cpp | 2 +- .../valuesource/birthdayparty.cpp | 2 +- .../chapter5-listproperties/piechart.cpp | 3 ++- .../chapter6-plugins/import/piechart.cpp | 3 ++- 12 files changed, 39 insertions(+), 11 deletions(-) (limited to 'examples/qml') 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 BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const 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 BirthdayParty::guests() { - return QQmlListProperty(this, m_guests); + return QQmlListProperty(this, &m_guests); } int BirthdayParty::guestCount() const 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 BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const 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 BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const 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 BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const 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 BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const 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 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* list, Person* p) { @@ -103,6 +115,16 @@ void BirthdayParty::clearGuests(QQmlListProperty* list) { reinterpret_cast< BirthdayParty* >(list->data)->clearGuests(); } +void BirthdayParty::replaceGuest(QQmlListProperty *list, int i, Person *p) +{ + reinterpret_cast< BirthdayParty* >(list->data)->replaceGuest(i, p); +} + +void BirthdayParty::removeLastGuest(QQmlListProperty *list) +{ + reinterpret_cast< BirthdayParty* >(list->data)->removeLastGuest(); +} + Person* BirthdayParty::guest(QQmlListProperty* 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 fb8b63a79d..a5704972cc 100644 --- a/examples/qml/referenceexamples/properties/birthdayparty.h +++ b/examples/qml/referenceexamples/properties/birthdayparty.h @@ -79,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*); static int guestCount(QQmlListProperty*); static Person* guest(QQmlListProperty*, int); static void clearGuests(QQmlListProperty*); + static void replaceGuest(QQmlListProperty*, int, Person*); + static void removeLastGuest(QQmlListProperty*); Person *m_host; QVector m_guests; 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 BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const 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 BirthdayParty::guests() { - return {this, m_guests}; + return {this, &m_guests}; } int BirthdayParty::guestCount() const 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 PieChart::slices() { - return QQmlListProperty(this, nullptr, &PieChart::append_slice, nullptr, nullptr, nullptr); + return QQmlListProperty(this, nullptr, &PieChart::append_slice, nullptr, + nullptr, nullptr, nullptr, nullptr); } void PieChart::append_slice(QQmlListProperty *list, PieSlice *slice) 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 PieChart::slices() { - return QQmlListProperty(this, nullptr, &PieChart::append_slice, nullptr, nullptr, nullptr); + return QQmlListProperty(this, nullptr, &PieChart::append_slice, nullptr, + nullptr, nullptr, nullptr, nullptr); } void PieChart::append_slice(QQmlListProperty *list, PieSlice *slice) -- cgit v1.2.3 From 38c03709236f6a2114ace7adf1b6bdcdfe8e4e18 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 11 Feb 2020 16:50:43 +0100 Subject: Doc: Fix "Extending QML" documentation It mentioned qmlRegisterType where that didn't exist anymore. Change-Id: If3e8c8ada746c720bff216df8c5f3fb618e09205 Reviewed-by: Simon Hausmann --- examples/qml/doc/src/qml-extending.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/qml') diff --git a/examples/qml/doc/src/qml-extending.qdoc b/examples/qml/doc/src/qml-extending.qdoc index 1ad3ae9a10..723e470d45 100644 --- a/examples/qml/doc/src/qml-extending.qdoc +++ b/examples/qml/doc/src/qml-extending.qdoc @@ -69,7 +69,7 @@ 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. -- cgit v1.2.3 From 90b4528b846542bfa6f0723487315140b9de17b4 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 17 Sep 2019 18:10:59 +0200 Subject: Avoid discouraged patterns in examples In particular, use required properties where applicable, explicitly import QtQml where we use it, avoid unqualified access into the root scope of a component, use JavaScript functions with explicit parameters as signal handlers. Change-Id: I3eaaba47cc3c7a2a12d488e36f9eec145cedbb0e Reviewed-by: Fabian Kosmale Reviewed-by: Shawn Rutledge --- examples/qml/referenceexamples/binding/example.qml | 2 +- examples/qml/referenceexamples/signal/example.qml | 2 +- examples/qml/referenceexamples/valuesource/example.qml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/qml') 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/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/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 { -- cgit v1.2.3 From 8bc51b89a1d71ca9c6b1595ce497e0d91e9d2634 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 17 Feb 2020 13:38:12 +0100 Subject: Doc: Fix extension plugin examples and documentation We advertise the usage of QQmlEngineExtensionPlugin, as registerTypes() should be avoided if possible. The actual source code of the examples already does this, but some of the includes and the documentation was lagging. Task-number: QTBUG-81615 Change-Id: Ibbee60ad55114bf6dc07875080c963e727f49e6b Reviewed-by: Fabian Kosmale Reviewed-by: Mitch Curtis --- examples/qml/qmlextensionplugins/doc/src/qmlpluginex.qdoc | 2 +- examples/qml/qmlextensionplugins/plugin.cpp | 2 +- .../qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/qml') 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 99d8c5378c..ae5f35bf5f 100644 --- a/examples/qml/qmlextensionplugins/plugin.cpp +++ b/examples/qml/qmlextensionplugins/plugin.cpp @@ -48,7 +48,7 @@ ** ****************************************************************************/ -#include +#include #include //![plugin] 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 0b1cfcc8f1..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,7 +51,7 @@ #define CHARTSPLUGIN_H //![0] -#include +#include class ChartsPlugin : public QQmlEngineExtensionPlugin { -- cgit v1.2.3 From 8ccc86d31933054edc02487d29328e109e4a1bc4 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 12 Feb 2020 13:49:43 +0100 Subject: Doc: Update documentation for "extending" example It referred to qmlRegisterType() even though we don't call it anymore. Change-Id: Ib07e4428d032e789d705156ddc4c9589fd797c65 Reviewed-by: Fabian Kosmale --- .../qml/tutorials/extending-qml/chapter1-basics/chapter1-basics.pro | 2 ++ 1 file changed, 2 insertions(+) (limited to 'examples/qml') 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 294a9ad0e8..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,8 +1,10 @@ QT += qml quick +#![0] CONFIG += qmltypes QML_IMPORT_NAME = Charts QML_IMPORT_MAJOR_VERSION = 1 +#![0] HEADERS += piechart.h SOURCES += piechart.cpp \ -- cgit v1.2.3 From 1fef24732bb5114392626a7fef956625a6cc66ac Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Thu, 27 Feb 2020 12:10:55 +0200 Subject: Examples: Add *.pro projects for existing *.qmlproject The *.qmlproject won't deploy and run on Android, thus adding normal .pro projects to allow deploying to Android. Task-number: QTBUG-80717 Change-Id: I8a79a56bec57add315c08088a2fca5995df76912 Reviewed-by: Ulf Hermann --- examples/qml/dynamicscene/dynamicscene.pro | 9 ++++++ examples/qml/dynamicscene/dynamicscene.qrc | 19 +++++++++++ examples/qml/dynamicscene/main.cpp | 51 ++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 examples/qml/dynamicscene/dynamicscene.pro create mode 100644 examples/qml/dynamicscene/dynamicscene.qrc create mode 100644 examples/qml/dynamicscene/main.cpp (limited to 'examples/qml') 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 @@ + + + dynamicscene.qml + content/images/face-smile.png + content/images/moon.png + content/images/NOTE + content/images/rabbit_brown.png + content/images/rabbit_bw.png + content/images/star.png + content/images/sun.png + content/images/tree_s.png + content/Button.qml + content/GenericSceneItem.qml + content/itemCreation.js + content/PaletteItem.qml + content/PerspectiveItem.qml + content/Sun.qml + + diff --git a/examples/qml/dynamicscene/main.cpp b/examples/qml/dynamicscene/main.cpp new file mode 100644 index 0000000000..e28375158d --- /dev/null +++ b/examples/qml/dynamicscene/main.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** 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 "../../quick/shared/shared.h" +DECLARATIVE_EXAMPLE_MAIN(dynamicscene) -- cgit v1.2.3 From 069afedec9e42c1d3ce6673a405337dfbc309992 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Wed, 4 Mar 2020 17:22:11 +0200 Subject: Examples: add .pro project for qml-i18n example Currently only the .qmlproject is available for this project, which won't deploy on Android, thus adding .pro project files. Also, since the translation won't work without the *.qm files being present as resources, those files are included by default with example. Task-number: QTBUG-80717 Change-Id: I86ac6c4097e4207b7f62d628f9a72439e78639db Reviewed-by: Ulf Hermann --- examples/qml/qml-i18n/doc/src/i18n.qdoc | 2 + examples/qml/qml-i18n/i18n/base.ts | 2 +- examples/qml/qml-i18n/i18n/qml_en_AU.ts | 2 +- examples/qml/qml-i18n/i18n/qml_fr.ts | 2 +- examples/qml/qml-i18n/main.cpp | 68 +++++++++++++++++++++++++++++++++ examples/qml/qml-i18n/qml-i18n.pro | 17 +++++++++ examples/qml/qml-i18n/qml-i18n.qml | 10 +++-- examples/qml/qml-i18n/qml-i18n.qrc | 5 +++ 8 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 examples/qml/qml-i18n/main.cpp create mode 100644 examples/qml/qml-i18n/qml-i18n.pro create mode 100644 examples/qml/qml-i18n/qml-i18n.qrc (limited to 'examples/qml') 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 @@ qml-i18n - + Hello 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 @@ qml-i18n - + Hello G'day 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 @@ qml-i18n - + Hello Bonjour 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 +#include + +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 @@ + + + qml-i18n.qml + + -- cgit v1.2.3 From f3dccc334f01d088fcdf1c2016c8153fe6154b61 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 7 Jan 2020 11:37:01 +0100 Subject: Adapt to the the new QMetaType change Fixes: QTBUG-82453 Change-Id: I7e5682945a07c3af183becd3947a69568f139d16 Reviewed-by: Fabian Kosmale --- .../qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h | 1 + 1 file changed, 1 insertion(+) (limited to 'examples/qml') diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h index b762ce1c49..855ad7ae3a 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/piechart.h @@ -61,6 +61,7 @@ class PieChart : public QQuickItem Q_PROPERTY(PieSlice* pieSlice READ pieSlice WRITE setPieSlice) //![0] Q_PROPERTY(QString name READ name WRITE setName) + Q_MOC_INCLUDE("pieslice.h") QML_ELEMENT //![1] public: -- cgit v1.2.3