Use QZXing in qml
-
Hi all,
at the moment I am trying to use QZXing in my qml.
But I am failing.
If I try to compile I get the following error: "undefined reference to 'QZXing::registerQMLTypes()'"
But decoding the qr code of an image in main() works.What I have done so far:
-
Downloaded QZXing source and compiled it to get libQZXing.so.
-
xxx.pro file:
QT += core gui qml quick widgets multimedia ... LIBS += -L$$PWD/QZXing/ -lQZXing INCLUDEPATH += $$PWD/QZXing DEPENDPATH += $$PWD/QZXing
-
main.cpp:
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QZXing.h> int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QZXing::registerQMLTypes(); QQmlApplicationEngine engine; engine.load(QUrl(QLatin1String("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; QImage qrCodeimageToDecode("/xxx/qrcode.png"); QZXing decoder; decoder.setDecoder(QZXing::DecoderFormat_QR_CODE); QString resultQrCode = decoder.decodeImage(qrCodeimageToDecode); return app.exec(); }
Any ideas what I am doing wrong?
-
-
Hi all,
at the moment I am trying to use QZXing in my qml.
But I am failing.
If I try to compile I get the following error: "undefined reference to 'QZXing::registerQMLTypes()'"
But decoding the qr code of an image in main() works.What I have done so far:
-
Downloaded QZXing source and compiled it to get libQZXing.so.
-
xxx.pro file:
QT += core gui qml quick widgets multimedia ... LIBS += -L$$PWD/QZXing/ -lQZXing INCLUDEPATH += $$PWD/QZXing DEPENDPATH += $$PWD/QZXing
-
main.cpp:
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QZXing.h> int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QZXing::registerQMLTypes(); QQmlApplicationEngine engine; engine.load(QUrl(QLatin1String("qrc:/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; QImage qrCodeimageToDecode("/xxx/qrcode.png"); QZXing decoder; decoder.setDecoder(QZXing::DecoderFormat_QR_CODE); QString resultQrCode = decoder.decodeImage(qrCodeimageToDecode); return app.exec(); }
Any ideas what I am doing wrong?
@MHermann said in Use QZXing as library in qml:
Any ideas what I am doing wrong?
are you sure the
libQZXing.so
relies in$$PWD/QZXing/
?? -
-
@MHermann said in Use QZXing as library in qml:
Any ideas what I am doing wrong?
are you sure the
libQZXing.so
relies in$$PWD/QZXing/
??@raven-worx : Yes, I compiled it and copied it there.
-
@MHermann said in Use QZXing as library in qml:
Any ideas what I am doing wrong?
are you sure the
libQZXing.so
relies in$$PWD/QZXing/
??@raven-worx :
The three linesQZXing decoder; decoder.setDecoder(QZXing::DecoderFormat_QR_CODE); QString resultQrCode = decoder.decodeImage(qrCodeimageToDecode);
are executing without problems. And they are also used from libQZXing.so.
-
@raven-worx :
The three linesQZXing decoder; decoder.setDecoder(QZXing::DecoderFormat_QR_CODE); QString resultQrCode = decoder.decodeImage(qrCodeimageToDecode);
are executing without problems. And they are also used from libQZXing.so.
are executing without problems. And they are also used from libQZXing.so.
Yes i overread that.
seems the
QZXING_QML
macro definition is missing.
Recompile the lib withCONFIG += qzxing_qml
-
are executing without problems. And they are also used from libQZXing.so.
Yes i overread that.
seems the
QZXING_QML
macro definition is missing.
Recompile the lib withCONFIG += qzxing_qml
@raven-worx :
I added the lineCONFIG += qzxing_qml
to QZXing.pro and compiled the lib again.
I copied the new *.so files to my directory.
But it behaves exactly the same...
"undefined reference to `QZXing::registerQMLTypes()'"I forgot to mention, that I also added additional arguments in my project:
DEFINES+=QZXING_QML DEFINES+=QML_MULTIMEDIA
Any more ideas?
-
@raven-worx :
I added the lineCONFIG += qzxing_qml
to QZXing.pro and compiled the lib again.
I copied the new *.so files to my directory.
But it behaves exactly the same...
"undefined reference to `QZXing::registerQMLTypes()'"I forgot to mention, that I also added additional arguments in my project:
DEFINES+=QZXING_QML DEFINES+=QML_MULTIMEDIA
Any more ideas?
@MHermann said in Use QZXing as library in qml:
Any more ideas?
No, this seemed pretty much the cause for issue to me.
Alternatively - if its's an option for you - you could add
include($$PWD/QZXing/src/QZXing.pri
(and also addCONFIG += qzxing_qml
) to your application's .pro file. Then QZXing is compiled into your binary directly. -
@MHermann said in Use QZXing as library in qml:
Any more ideas?
No, this seemed pretty much the cause for issue to me.
Alternatively - if its's an option for you - you could add
include($$PWD/QZXing/src/QZXing.pri
(and also addCONFIG += qzxing_qml
) to your application's .pro file. Then QZXing is compiled into your binary directly.This could also be a solution. But this would not be my preferred solution...
That would mean that the whole QZXing source code will be compiled too, each time I am compiling my own source code.
Or is it possible to exclude this from the compiling process and compile it only once? -
This could also be a solution. But this would not be my preferred solution...
That would mean that the whole QZXing source code will be compiled too, each time I am compiling my own source code.
Or is it possible to exclude this from the compiling process and compile it only once?@MHermann
it gets only recompiled when it needs to (when a source file changes, etc) -
@MHermann
it gets only recompiled when it needs to (when a source file changes, etc)I added the QZXing source code via
include($$PWD/QZXing/src/QZXing.pri
Now it is working.
-
Hi! If your project is based on C++, consider using SCodes. SCodes uses latest ZXing C++ port. It also allows you to generate QR/Bar codes. You can read more about it here.
-
Hi! If your project is based on C++, consider using SCodes. SCodes uses latest ZXing C++ port. It also allows you to generate QR/Bar codes. You can read more about it here.
@lukas_kosinski unfortunately SCodes only supports Code128 and QR
-
@lukas_kosinski unfortunately SCodes only supports Code128 and QR
@ekkescorner I worked on that and now it supports much more formats. Currently it's a PR opened, but it should be soon merged:
https://github.com/scytheStudio/SCodes/pull/11Sorry that I add the comment to a quite old post. I simply wanted people to know it and not be misled.