From ee596f183329a661efc52f7d6ce2c60dc8f387f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Thu, 11 Apr 2019 12:58:02 +0200 Subject: [PATCH 1/2] Add QMLPlugin class for registring as a qml plugin --- src/QZXing.pri | 20 ++++++++++++++++++-- src/QZXingPlugin.cpp | 24 ++++++++++++++++++++++++ src/QZXingPlugin.h | 15 +++++++++++++++ src/qmldir | 4 ++++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/QZXingPlugin.cpp create mode 100644 src/QZXingPlugin.h create mode 100644 src/qmldir diff --git a/src/QZXing.pri b/src/QZXing.pri index f0976c90..b940d2fb 100644 --- a/src/QZXing.pri +++ b/src/QZXing.pri @@ -282,13 +282,24 @@ qzxing_qml { greaterThan(QT_VERSION, 4.7): lessThan(QT_VERSION, 5.0): QT += declarative greaterThan(QT_MAJOR_VERSION, 4): QT += quick + CONFIG+= plugin + DEFINES += QZXING_QML HEADERS += \ - $$PWD/QZXingImageProvider.h + $$PWD/QZXingImageProvider.h \ + $$PWD/QZXingPlugin.h SOURCES += \ - $$PWD/QZXingImageProvider.cpp + $$PWD/QZXingImageProvider.cpp \ + $$PWD/QZXingPlugin.cpp + + plugin.files =+ \ + qmldir + + importPath = $$[QT_INSTALL_QML]/QZXing + plugin.path = $${importPath} + target.path = $${importPath} } symbian { @@ -328,6 +339,11 @@ symbian { QMAKE_PKGCONFIG_INCDIR = ${prefix}/include unix:QMAKE_CLEAN += -r pkgconfig lib$${TARGET}.prl + importPath = $$[QT_INSTALL_QML]/QZXing + target.path = $${importPath} + qzxing_qml { + INSTALLS+=plugin +} } win32-msvc*{ diff --git a/src/QZXingPlugin.cpp b/src/QZXingPlugin.cpp new file mode 100644 index 00000000..53f1055b --- /dev/null +++ b/src/QZXingPlugin.cpp @@ -0,0 +1,24 @@ +#include "QZXingPlugin.h" +#include "QZXing.h" +#include +#ifdef QZXING_MULTIMEDIA +#include +#endif +#include "QZXingImageProvider.h" + +void QZXingPlugin::registerTypes(const char *uri) +{ + Q_ASSERT(uri == QLatin1String("QZXing")); + qmlRegisterType("QZXing", 2, 3, "QZXing"); + +#ifdef QZXING_MULTIMEDIA + qmlRegisterType("QZXing", 2, 3, "QZXingFilter"); +#endif //QZXING_MULTIMEDIA + qmlProtectModule(uri, 2); +} + +void QZXingPlugin::initializeEngine(QQmlEngine *engine, const char *uri) +{ + Q_UNUSED(uri) + engine->addImageProvider(QLatin1String("QZXing"), new QZXingImageProvider()); +} diff --git a/src/QZXingPlugin.h b/src/QZXingPlugin.h new file mode 100644 index 00000000..05bff4ed --- /dev/null +++ b/src/QZXingPlugin.h @@ -0,0 +1,15 @@ +#ifndef QXZINGPLUGIN_H +#define QXZINGPLUGIN_H +#include +#include + +class QZXingPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) +public: + void registerTypes(const char *uri) override; + void initializeEngine(QQmlEngine *engine, const char *uri) override; +}; + +#endif // QXZINGPLUGIN_H diff --git a/src/qmldir b/src/qmldir new file mode 100644 index 00000000..16334fd7 --- /dev/null +++ b/src/qmldir @@ -0,0 +1,4 @@ +module QZXing +plugin QZXing +classname QZXingPlugin +depends QtMultimedia 5.5 From 961e24f9f1d7e7d1679a5fad0950fa73460fca70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Bidar?= Date: Tue, 16 Apr 2019 11:47:19 +0200 Subject: [PATCH 2/2] Disable methods to register QMLtypes if QZXing is build as lib + qml --- src/QZXing.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/QZXing.cpp b/src/QZXing.cpp index 4f81ea96..5ca8e987 100644 --- a/src/QZXing.cpp +++ b/src/QZXing.cpp @@ -79,6 +79,8 @@ QZXing::QZXing(QZXing::DecoderFormat decodeHints, QObject *parent) : QObject(par #ifdef QZXING_QML +#ifndef DISABLE_LIBRARY_FEATURES + #if QT_VERSION >= 0x040700 void QZXing::registerQMLTypes() { @@ -98,6 +100,8 @@ void QZXing::registerQMLImageProvider(QQmlEngine& engine) } #endif //QT_VERSION >= Qt 5.0 +#endif // DISABLE_LIBRARY_FEATURES + #endif //QZXING_QML void QZXing::setTryHarder(bool tryHarder)