2016-08-10 15:16:59 +00:00
# qzxing
2018-02-12 19:09:54 +00:00
Qt/QML wrapper library for the [ZXing ](https://github.com/zxing/zxing ) barcode image processing library.
2016-08-10 15:16:59 +00:00
Supports barcode decoding for the following types:
* UPC-A
* UPC-E
* EAN-8
* EAN-13
* ITF
* Code 39
* Code 93
2017-07-08 18:09:26 +00:00
* Code 128 (GS1)
2016-08-10 15:16:59 +00:00
* Codabar
* QR Code
* Data Matrix
* Aztec (beta)
2017-07-08 18:09:26 +00:00
* PDF 417
2018-02-12 19:09:54 +00:00
Supports barcode encoding for the following types:
* QR Code
# Table of contents
1. [How to include ](#howToInclude )
1. [Embed the source code ](#embedInSourceCode )
1. [Compile the project as an external library ](#externalLibrary )
2018-02-12 19:19:03 +00:00
1. [Control dependencies ](#controlDependencies )
1. [QZXing (core) ](#controlDependenciesCore )
1. [QZXing (core + QML) ](#controlDependenciesCoreQML )
1. [QZXing + QZXingFilter ](#controlDependenciesCoreQMLQZXingFilter )
2018-02-12 19:09:54 +00:00
1. [How to use ](#howTo )
1. [Decoding operation ](#howToDecoding )
2018-02-12 19:19:03 +00:00
1. [C++/Qt ](#howToDecodingCPP )
1. [Qt Quick ](#howToDecodingQtQuick )
1. [Encoding operation ](#howToEncoding )
1. [C++/Qt ](#howToEncodingCPP )
1. [Qt Quick ](#howToEncodingQtQuick )
2018-02-15 09:38:57 +00:00
1. [Encoded text format Information ](#howToEncodingFormatExamples )
2018-02-12 19:09:54 +00:00
1. [Contact ](#contact )
2018-02-12 19:19:03 +00:00
< a name = "howToInclude" > < / a >
# How to include
2017-01-16 17:58:34 +00:00
The project can be used in two ways:
2018-02-12 19:19:03 +00:00
< a name = "embedInSourceCode" > < / a >
## Embed the source code.
2017-01-16 17:58:34 +00:00
Copy source code folder of QZXing to the root of your project. Add the following line to your .pro file. For more information see [here ](https://github.com/ftylitak/qzxing/wiki/Using-the-QZXing-through-the-source-code ).
2017-07-21 08:24:08 +00:00
```qmake
include(QZXing/QZXing.pri)
```
2018-02-12 19:19:03 +00:00
< a name = "externalLibrary" > < / a >
## Compile the project as an external library
2017-01-16 17:58:34 +00:00
Open QZXing project (QZXing.pro) and compile. If it is needed to compile as static library, uncomment the following line in the .pro file.
2017-07-21 08:24:08 +00:00
```qmake
CONFIG += staticlib
```
2018-02-12 19:19:03 +00:00
< a name = "controlDependencies" > < / a >
## Control dependencies
2017-01-16 17:58:34 +00:00
Project file config tags are now introduced to be able to control the dependencies of the library accoring to the needs.
The core part requires only "core" and "gui" Qt modules. Though for backward compatibility "quick" Qt module is also required.
The 3 level of dependencies are:
2018-02-12 19:19:03 +00:00
< a name = "controlDependenciesCore" > < / a >
### QZXing (core)
2017-03-20 15:23:52 +00:00
By including QZXing.pri or by building QZXing.pro you get the core functionality of QZXing which requires only QtCore and QtGui (because of QImage).
2017-01-16 17:58:34 +00:00
2017-03-20 15:23:52 +00:00
Warning! The initial default configuration till 20/03/2017 was including qzxing_qml. This tag could not be removed once added, so it was needed to be removed from the defaults.
2018-02-12 19:19:03 +00:00
< a name = "controlDependenciesCoreQML" > < / a >
### QZXing (core + QML)
2017-03-20 15:23:52 +00:00
If an application is going to use QML functionality, it is now possible to add the dependency to it. This can be done by adding the folloing line to the .pro file of its project:
2017-01-16 17:58:34 +00:00
2017-07-21 08:24:08 +00:00
```qmake
CONFIG += qzxing_qml
```
2018-02-12 19:19:03 +00:00
< a name = "controlDependenciesCoreQMLQZXingFilter" > < / a >
### QZXing + QZXingFilter
2017-03-20 15:23:52 +00:00
QZXing includes QZXingFilter, a QAbstractVideoFilter implementation to provide a mean of providing live feed to the decoding library. It automatically includes QML implementation as well.
2017-01-16 17:58:34 +00:00
This option requires "multimedia" Qt module this is why it is considered as a separate configuration. It can be used by adding the folloing line to the .pro file of a project:
2017-07-21 08:24:08 +00:00
```qmake
CONFIG += qzxing_multimedia
```
2018-02-12 19:19:03 +00:00
< a name = "howTo" > < / a >
# How to use
2017-01-16 17:58:34 +00:00
Follows simple code snippets that brefly show the use of the library. For more details advise the examples included in the repository and the [wiki ](https://github.com/ftylitak/qzxing/wiki ).
2018-02-12 19:19:03 +00:00
< a name = "howToDecoding" > < / a >
## Decoding operation
2018-02-12 19:09:54 +00:00
2018-02-12 19:19:03 +00:00
< a name = "howToDecodingCPP" > < / a >
### C++/Qt
2017-01-16 17:58:34 +00:00
2017-07-21 08:24:08 +00:00
```cpp
#include <QZXing.h>
int main()
{
QImage imageToDecode("file.png");
QZXing decoder;
decoder.setDecoder( DecoderFormat_QR_CODE | DecoderFormat_EAN_13 );
QString result = decoder.decodeImage(imageToDecode);
}
```
2017-01-16 17:58:34 +00:00
2018-02-12 19:19:03 +00:00
< a name = "howToDecodingQtQuick" > < / a >
### Qt Quick
2017-01-16 17:58:34 +00:00
First register QZXing type to the QML engine.
2017-07-21 08:24:08 +00:00
```cpp
#include <QZXing.h>
2017-01-16 17:58:34 +00:00
2017-07-21 08:24:08 +00:00
int main()
{
...
QZXing::registerQMLTypes();
...
}
```
2017-01-16 17:58:34 +00:00
The in the QML file
2017-07-21 08:24:08 +00:00
```qml
import QZXing 2.3
2017-01-16 17:58:34 +00:00
2017-07-21 08:24:08 +00:00
function decode(preview) {
imageToDecode.source = preview
decoder.decodeImageQML(imageToDecode);
}
2017-01-16 17:58:34 +00:00
2017-07-21 08:24:08 +00:00
Image{
id:imageToDecode
}
2017-01-16 17:58:34 +00:00
2017-07-21 08:24:08 +00:00
QZXing{
id: decoder
2017-01-16 17:58:34 +00:00
2017-07-21 08:24:08 +00:00
enabledDecoders: QZXing.DecoderFormat_QR_CODE
2017-01-16 17:58:34 +00:00
2017-07-21 08:24:08 +00:00
onDecodingStarted: console.log("Decoding of image started...")
2017-01-16 17:58:34 +00:00
2017-07-21 08:24:08 +00:00
onTagFound: console.log("Barcode data: " + tag)
2017-01-16 17:58:34 +00:00
2017-07-21 08:24:08 +00:00
onDecodingFinished: console.log("Decoding finished " + (succeeded==true ? "successfully" : "unsuccessfully") )
}
```
2017-01-16 17:58:34 +00:00
2018-02-12 19:19:03 +00:00
< a name = "howToEncoding" > < / a >
## Encoding operation
2018-02-12 19:09:54 +00:00
2018-02-12 19:19:03 +00:00
< a name = "howToEncodingCPP" > < / a >
### C++/Qt
2018-02-12 19:09:54 +00:00
The encoding function has been written as static as it does not have any dependencies to data other than the ones provided by the arguments.
Use the encoding function with its default settings:
* Format: QR Code
* Size: 240x240
* Error Correction Level: Low (L)
```cpp
2018-02-12 19:49:20 +00:00
#include <QZXing.h>
int main()
{
QString data = "text to be encoded";
QImage barcode = QZXing::encodeData(data);
}
2018-02-12 19:09:54 +00:00
```
Or use the encoding function with custom settings:
```cpp
QString data = "text to be encoded";
QImage barcode = QZXing::encodeData(data, QZXing::EncoderFormat_QR_CODE,
QSize(width.toInt(), height.toInt()), QZXing::EncodeErrorCorrectionLevel_H);
```
2018-02-12 19:19:03 +00:00
< a name = "howToEncodingQtQuick" > < / a >
### Qt Quick
2018-02-12 19:09:54 +00:00
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.
Default settings:
```qml
2018-02-12 19:50:58 +00:00
import QZXing 2.3
2018-02-12 19:09:54 +00:00
TextField {
id: inputField
text: "Hello world!"
}
Image{
source: "image://QZXing/encode/" + inputField.text;
cache: false;
}
```
2018-03-11 17:21:19 +00:00
Or use the encoding function with the optional custom settings that are passed like URL query parameters:
2018-02-12 19:09:54 +00:00
| attribute name | value | description |
| -------------- | ---------- | --------------------------------------------- |
| corretionLevel | L, M, Q, H | the error correction level |
| format | qrcode | the encode formatter. Currently only QR Code. |
2018-03-11 17:21:19 +00:00
the size of the image can be adjusted by using the Image.sourceWidth and Image.sourceHeight properties of Image QML element.
2018-02-12 19:09:54 +00:00
```qml
2018-02-12 19:49:20 +00:00
import QZXing 2.3
2018-02-12 19:09:54 +00:00
TextField {
id: inputField
text: "Hello world!"
}
Image{
source: "image://QZXing/encode/" + inputField.text +
2018-03-11 17:21:19 +00:00
"?corretionLevel=M" +
2018-02-12 19:09:54 +00:00
"& format=qrcode"
2018-03-11 17:21:19 +00:00
sourceSize.width: 320
sourceSize.height: 320
2018-02-12 19:09:54 +00:00
}
```
2018-02-15 09:38:57 +00:00
< a name = "howToEncodingFormatExamples" > < / a >
### Encoded text format Information
Here is a list of contents that have been encoded and tested to be recognizable by the Android ZXing decoding application:
[QR Code encoding wiki page ](https://github.com/ftylitak/qzxing/wiki/QR-Code-encoding )
2018-02-12 19:19:03 +00:00
< a name = "contact" > < / a >
# Contact
2016-08-11 15:21:10 +00:00
In case of bug reports or feature requests feel free to open an [issue ](https://github.com/ftylitak/qzxing/issues ).