Skip to content

Commit fdbe3ca

Browse files
committed
Add QMLPlugin class for registring as a qml plugin
1 parent 0211eed commit fdbe3ca

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

src/QZXing.pri

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,28 @@ qzxing_qml {
282282
greaterThan(QT_VERSION, 4.7): lessThan(QT_VERSION, 5.0): QT += declarative
283283
greaterThan(QT_MAJOR_VERSION, 4): QT += quick
284284

285+
CONFIG+= plugin
286+
285287
DEFINES += QZXING_QML
286288

287289
HEADERS += \
288290
$$PWD/QZXingImageProvider.h
289291

290292
SOURCES += \
291293
$$PWD/QZXingImageProvider.cpp
294+
295+
HEADERS += \
296+
qxzingplugin.h
297+
298+
SOURCES += \
299+
qxzingplugin.cpp
300+
301+
plugin.files =+ \
302+
qmldir
303+
304+
importPath = $$[QT_INSTALL_QML]/QZXing
305+
plugin.path = $${importPath}
306+
target.path = $${importPath}
292307
}
293308

294309
symbian {
@@ -328,6 +343,11 @@ symbian {
328343
QMAKE_PKGCONFIG_INCDIR = ${prefix}/include
329344

330345
unix:QMAKE_CLEAN += -r pkgconfig lib$${TARGET}.prl
346+
importPath = $$[QT_INSTALL_QML]/QZXing
347+
target.path = $${importPath}
348+
qzxing_qml {
349+
INSTALLS+=plugin
350+
}
331351
}
332352

333353
win32-msvc*{

src/qmldir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module QZXing
2+
plugin QZXing
3+
classname QZXingPlugin
4+
depends QtMultimedia 5.5

src/qxzingplugin.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "qxzingplugin.h"
2+
#include "QZXing.h"
3+
#include <QtQml/qqml.h>
4+
#ifdef QZXING_MULTIMEDIA
5+
#include <QZXingFilter.h>
6+
#endif
7+
8+
void QZXingPlugin::registerTypes(const char *uri)
9+
{
10+
Q_ASSERT(uri == QLatin1String("QZXing"));
11+
qmlRegisterType<QZXing>("QZXing", 2, 3, "QZXing");
12+
13+
#ifdef QZXING_MULTIMEDIA
14+
qmlRegisterType<QZXingFilter>("QZXing", 2, 3, "QZXingFilter");
15+
#endif //QZXING_MULTIMEDIA
16+
qmlProtectModule(uri, 2);
17+
}

src/qxzingplugin.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef QXZINGPLUGIN_H
2+
#define QXZINGPLUGIN_H
3+
#include <QtQml/QQmlExtensionPlugin>
4+
5+
class QZXingPlugin : public QQmlExtensionPlugin
6+
{
7+
Q_OBJECT
8+
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
9+
public:
10+
void registerTypes(const char *uri) override;
11+
};
12+
13+
#endif // QXZINGPLUGIN_H

0 commit comments

Comments
 (0)