Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add QMLPlugin class for registring as a qml plugin #102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/QZXing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ QZXing::QZXing(QZXing::DecoderFormat decodeHints, QObject *parent) : QObject(par

#ifdef QZXING_QML

#ifndef DISABLE_LIBRARY_FEATURES
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed as this macro refers to the integration method of the library, not to the functionality itself.

Thus the same comment applies to the closing of the ifdef.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But its needed on static builds and not on dynamic builds.
I thought that macro was to check if no dynamic build was built.


#if QT_VERSION >= 0x040700
void QZXing::registerQMLTypes()
{
Expand All @@ -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)
Expand Down
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 "QZXingPlugin.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