Skip to content

Commit

Permalink
Update in README.md to include missing info on how to use Barcode Enc…
Browse files Browse the repository at this point in the history
…oder feature. Also added warning (in debug mode) if trying to use Encoder feature through QML through feature is not enabled.
  • Loading branch information
ftylitak committed Nov 10, 2020
1 parent f5cee9c commit 63850d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ QZXing{
<a name="howToEncoding"></a>
## 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)
```

<a name="howToEncodingCPP"></a>
### C++/Qt

Expand Down Expand Up @@ -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/<data_to_be_encoded>". 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
Expand Down
5 changes: 5 additions & 0 deletions src/QZXingImageProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 63850d5

Please sign in to comment.