From 63850d5f0326aaf7a9bbf6ef276bdc4f4ab583f3 Mon Sep 17 00:00:00 2001 From: Nikolaos Ftylitakis Date: Tue, 10 Nov 2020 10:20:38 +0200 Subject: [PATCH] Update in README.md to include missing info on how to use Barcode Encoder feature. Also added warning (in debug mode) if trying to use Encoder feature through QML through feature is not enabled. --- README.md | 17 +++++++++++++++++ src/QZXingImageProvider.cpp | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 38bc3b8..7433236 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,14 @@ QZXing{ ## Encoding operation +To begin with, make sure the Encoder feature is enabled. If __QZXing.pri__ is used, then the feature is already enabled. If your project uses __QZXing-compoents.pri__ instead, do add the following CONFIG in your .pro file: + +```pro +CONFIG += enable_encoder_qr_code + +include(QZXing/QZXing-components.pri) +``` + ### C++/Qt @@ -204,6 +212,15 @@ QImage barcode = QZXing::encodeData(data, QZXing::EncoderFormat_QR_CODE, The encoding function can be easily used in QML through QZXing's Image Provider: "image://QZXing/encode/". As with the C++ example, it can either be used with the default settings or with custom settings. +First register the custom Image Provider in the __main.cpp__: + +```cpp +QQmlApplicationEngine engine; + +QZXing::registerQMLTypes(); +QZXing::registerQMLImageProvider(engine); +``` + Default settings: ```qml diff --git a/src/QZXingImageProvider.cpp b/src/QZXingImageProvider.cpp index 9577095..4e25c0e 100644 --- a/src/QZXingImageProvider.cpp +++ b/src/QZXingImageProvider.cpp @@ -70,11 +70,16 @@ QImage QZXingImageProvider::requestImage(const QString &id, QSize *size, const Q data = id.mid(slashIndex + 1); } +#ifdef ENABLE_ENCODER_GENERIC QZXingEncoderConfig encoderConfig(format, requestedSize, correctionLevel, border, transparent); QString dataTemp(QUrl::fromPercentEncoding(data.toUtf8())); QImage result = QZXing::encodeData(dataTemp, encoderConfig); +#else + QImage result; + qDebug() << "barcode encoder disabled. Add 'CONFIG += enable_encoder_qr_code'"; +#endif *size = result.size(); return result; }