mirror of https://github.com/status-im/qzxing.git
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.
This commit is contained in:
parent
f5cee9c639
commit
63850d5f03
17
README.md
17
README.md
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue