diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-01-07 07:33:53 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-01-07 07:33:53 (GMT) |
commit | 78221020e2fd9370b0915a32cde81a95bdf44d87 (patch) | |
tree | 2c807d104f1e18b155de0d88d44b7749e42390a8 /examples/declarative/plugins | |
parent | 3b10e20d8230d1b6044ab5c96ffdb24bc37f85da (diff) | |
download | Qt-78221020e2fd9370b0915a32cde81a95bdf44d87.zip Qt-78221020e2fd9370b0915a32cde81a95bdf44d87.tar.gz Qt-78221020e2fd9370b0915a32cde81a95bdf44d87.tar.bz2 |
Load qmlmodules plugins.
This allows projects which use the declarative module to add QML types
through C++ modules, such that qmlviewer (or any QML) can import those
types.
Diffstat (limited to 'examples/declarative/plugins')
-rw-r--r-- | examples/declarative/plugins/README | 7 | ||||
-rw-r--r-- | examples/declarative/plugins/plugin.cpp | 94 | ||||
-rw-r--r-- | examples/declarative/plugins/plugins.pro | 12 | ||||
-rw-r--r-- | examples/declarative/plugins/plugins.qml | 23 |
4 files changed, 136 insertions, 0 deletions
diff --git a/examples/declarative/plugins/README b/examples/declarative/plugins/README new file mode 100644 index 0000000..e67b1de --- /dev/null +++ b/examples/declarative/plugins/README @@ -0,0 +1,7 @@ +This example show a C++ plugin that provides additional modules of QML types +(in this case, a single module with a single extra type). +to run: + + make install + qmlviewer plugins.qml + diff --git a/examples/declarative/plugins/plugin.cpp b/examples/declarative/plugins/plugin.cpp new file mode 100644 index 0000000..ac44e7e --- /dev/null +++ b/examples/declarative/plugins/plugin.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtDeclarative/qmlmoduleplugin.h> +#include <QtDeclarative/qml.h> +#include <qdebug.h> +#include <qdatetime.h> +#include <qbasictimer.h> + +class Time : public QObject +{ + Q_OBJECT + Q_PROPERTY(int hour READ hour NOTIFY timeChanged) + Q_PROPERTY(int minute READ minute NOTIFY timeChanged) + +public: + Time(QObject *parent=0) : QObject(parent) + { + timerEvent(0); + timer.start(30000,this); + } + + int minute() const { return t.minute(); } + int hour() const { return t.hour(); } + +signals: + void timeChanged(); + +protected: + void timerEvent(QTimerEvent *) + { + t = QTime::currentTime(); + emit timeChanged(); + } + +private: + QBasicTimer timer; + QTime t; +}; + +QML_DECLARE_TYPE(Time); +QML_DEFINE_TYPE(com.nokia.TimeExample,1,0,Time,Time); + +class QExampleQmlPlugin : public QmlModulePlugin +{ + Q_OBJECT +public: + QStringList keys() const + { + return QStringList() << QLatin1String("com.nokia.TimeExample"); + } +}; + +#include "plugin.moc" + +Q_EXPORT_PLUGIN2(qtimeexampleqmlplugin, QExampleQmlPlugin); diff --git a/examples/declarative/plugins/plugins.pro b/examples/declarative/plugins/plugins.pro new file mode 100644 index 0000000..a1a94f9 --- /dev/null +++ b/examples/declarative/plugins/plugins.pro @@ -0,0 +1,12 @@ +TEMPLATE = lib +TARGET = qtimeexampleqmlplugin +CONFIG += qt plugin declarative + +SOURCES += plugin.cpp + +target.path += $$[QT_INSTALL_PLUGINS]/qmlmodules +INSTALLS += target + + +VERSION=1.0.0 + diff --git a/examples/declarative/plugins/plugins.qml b/examples/declarative/plugins/plugins.qml new file mode 100644 index 0000000..df6b5d4 --- /dev/null +++ b/examples/declarative/plugins/plugins.qml @@ -0,0 +1,23 @@ +import Qt 4.6 +import com.nokia.TimeExample 1.0 + +Item { + + Time { id: time } + + width: 200 + height: 100 + + Rectangle { + anchors.fill: parent + color: "blue" + } + + Text { + text: time.hour + ":" + (time.minute < 10 ? "0" : "") + time.minute + anchors.centerIn: parent + color: "white" + font.pixelSize: 42 + font.bold: true + } +} |