Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 57c230e

Browse files
committedApr 15, 2019
Add QMLPlugin class for registring as a qml plugin
1 parent 0211eed commit 57c230e

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed
 

‎src/QZXing.pri

+20
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+
$$PWD/QZXingPlugin.h
297+
298+
SOURCES += \
299+
$$PWD/QZXingPlugin.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/QZXingPlugin.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "qxzingplugin.h"
2+
#include "QZXing.h"
3+
#include <QtQml/qqml.h>
4+
#ifdef QZXING_MULTIMEDIA
5+
#include <QZXingFilter.h>
6+
#endif
7+
#include "QZXingImageProvider.h"
8+
9+
void QZXingPlugin::registerTypes(const char *uri)
10+
{
11+
Q_ASSERT(uri == QLatin1String("QZXing"));
12+
qmlRegisterType<QZXing>("QZXing", 2, 3, "QZXing");
13+
14+
#ifdef QZXING_MULTIMEDIA
15+
qmlRegisterType<QZXingFilter>("QZXing", 2, 3, "QZXingFilter");
16+
#endif //QZXING_MULTIMEDIA
17+
qmlProtectModule(uri, 2);
18+
}
19+
20+
void QZXingPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
21+
{
22+
Q_UNUSED(uri)
23+
engine->addImageProvider(QLatin1String("QZXing"), new QZXingImageProvider());
24+
}

‎src/QZXingPlugin.h

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

‎src/qmldir

+4
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

0 commit comments

Comments
 (0)
Please sign in to comment.