Skip to content

Commit

Permalink
Add QMLPlugin class for registring as a qml plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Thaodan committed Apr 16, 2019
1 parent 0211eed commit d0a9ee7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/QZXing.pri
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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*{
Expand Down
24 changes: 24 additions & 0 deletions src/QZXingPlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "qxzingplugin.h"
#include "QZXing.h"
#include <QtQml/qqml.h>
#ifdef QZXING_MULTIMEDIA
#include <QZXingFilter.h>
#endif
#include "QZXingImageProvider.h"

void QZXingPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("QZXing"));
qmlRegisterType<QZXing>("QZXing", 2, 3, "QZXing");

#ifdef QZXING_MULTIMEDIA
qmlRegisterType<QZXingFilter>("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());
}
15 changes: 15 additions & 0 deletions src/QZXingPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef QXZINGPLUGIN_H
#define QXZINGPLUGIN_H
#include <QtQml/QQmlExtensionPlugin>
#include <QQmlEngine>

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
4 changes: 4 additions & 0 deletions src/qmldir
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module QZXing
plugin QZXing
classname QZXingPlugin
depends QtMultimedia 5.5

0 comments on commit d0a9ee7

Please sign in to comment.