This project is Qt & Qml wrapper for ZXing-C++ Library that is used for decoding and generating 1D and 2D barcodes. This particular C++ ZXing port is one of the most recent C++ versions of popular ZXing library using modern compilers.
Thanks to SCodes you can start scanning barcodes in few steps. We used Qt 5.15.2 and Qt 6.3.0 to built wrapper and example applications, but it's compatible with older Qt versions as well.
Implementation of same method for both Qt version does not seems possible(check why). We have ported the SCodes wrapper to Qt6 by following the multimedia changes.
There are plenty of supported formats and we constantly work on adding new.
Format | Supports scanning | Supports generating |
---|---|---|
UPC-A | ✔️ | ✔️ |
UPC-E | ✔️ | ✔️ |
EAN-8 | ✔️ | ✔️ |
EAN-13 | ✔️ | ✔️ |
DataBar | ✔️ | ❌ |
DataBar Expanded | ❌ | ❌ |
Code 39 | ✔️ | ✔️ |
Code 93 | ✔️ | ✔️ |
Code 128 | ✔️ | ✔️ |
Codabar | ✔️ | ✔️ |
ITF | ❌ | ✔️ |
Format | Supports scanning | Supports generating |
---|---|---|
QR Code | ✔️ | ✔️ |
DataMatrix | ✔️ | ✔️ |
Aztec | ✔️ | ✔️ |
PDF417 | ✔️ | ✔️ |
MaxiCode | ❌ | ❌ |
Feel free to read "How to scan barcodes in Qt Qml application" blog post if you are interested in the details behind scanning mechanism. Also you can try out the QmlReaderExample in order to see how it is working.
SCodes supports generating barcodes as well. It is covered in "How to generate barcode in Qt Qml" application blog post. Also you can try out the QmlGeneratorExample in order to see how it is working.
Above blog posts contains step by step tutorial on how to do that for Qt5 version. For Qt6 (see here).
All you need to do is to follow these steps.
- Add SCodes as submodule, by typing
git submodule add git@gitlab.com:scythestudio/scodes.git
- Update submodule
git submodule update --recursive --init
(you can also put wrapper files to your project manually without adding submodule) - Add
include(scodes/src/SCodes.pri)
to your .pro file - If you want to use barcode reader functionality you need to register
SBarcodeFilter
class for Qt5 orSBarcodeScanner
class for Qt6. For both version, seperate them with if directive to register as we did in barcode reader example(how to register reader class). As for barcode generator functionality you just need to registerSBarcodeGenerator
class(how to register generator class). - Import SCodes in your Qml file
import com.scythestudio.scodes 1.0
- Import multimedia module
import QtMultimedia 5.15
for Qt5 orimport QtMultimedia
for Qt6. - If build fails, try to add
CONFIG += c++17
to your .pro file - You are done. Get inspired by Qt5 QML Barcode Reader demo or Qt6 QML Barcode Reader demo to test wrapper.
-
Add SCodes as submodule, by typing
git submodule add git@gitlab.com:scythestudio/scodes.git
-
Update submodule
git submodule update --recursive --init
(you can also put wrapper files to your project manually without adding submodule) -
Add to your project SCodes library
add_subdirectory(SCodes)
-
Link SCodes library to your library or executable.
target_link_libraries(${PROJECT_NAME} PUBLIC SCodes)
-
Import SCodes in your Qml file
import com.scythestudio.scodes 1.0
-
You are done. Get inspired by QML Barcode Reader demo to test wrapper.
Registering the barcode reader classes with if directive:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
qmlRegisterType<SBarcodeFilter>("com.scythestudio.scodes", 1, 0, "SBarcodeScanner");
#else
qmlRegisterType<SBarcodeScanner>("com.scythestudio.scodes", 1, 0, "SBarcodeScanner");
#endif
Registering the barcode generator class:
qmlRegisterType<SBarcodeGenerator>("com.scythestudio.scodes", 1, 0, "SBarcodeGenerator");
Qt's multimedia library has major changes. The most importants are, changes in QML VideoOutput
, absence of QVideoFilterRunnable
and QAbstractVideoFilter
classes in Qt6.
SCodes library is using SBarcodeFilter
class for Qt5 and SBarcodesScanner
class for Qt6 version.
VideoOutput QML element has major changes and it is not possible to use same QML files for both version. If you want to implement barcode reader functionality for both version you need to create two seperate QML file too(that's because of QML VideoOutput changes in multimedia module of Qt6). Check our QmlBarcodeReader example for more details.
SBarcodeFilter.cpp
and SBarcodesScanner.cpp
files included/excluded according to the Qt version in the SCodes CMakeLists file. The idea of excluding the related class according to Qt version is prevent to get error from not existing libraries when you compile the project for Qt6(e.g. QVideoFilterRunnable, QAbstractVideoFilter). Likewise in Qt5 for QVideoSink.
SBarcodeScanner class is inherited from QVideoSink class. First, QMediaCaptureSession class instantiated and in the constructor initCam()
function called to give QCamera and QVideoSink(the class itself) instances to QMediaCaptureSession instance as a parameter:
m_capture.setCamera(camera);
m_capture.setVideoSink(this);
Right after that camera started.
camera->start();
Also, in the constuctor, Worker
object that dependent on scanner variable passed to workerThread instance. So, we can access to resources of the scanner object.
worker->moveToThread(&workerThread);
VideoOutput
has a videoSink
property in Qt6(which holds C++ QVideoSink object that is used to render the video frames). This property assigned to m_videosink pointer of SBarcodeScanner
to be able to get frames from QML VideoOutput element. To handle the frames QVideoSink::videoFrameChanged
signal connected to SBarcodeScanner::handleFrameCaptured
slot.
As soon as new frame has came to the handle function;
emit process(QImage &img);
signal emitted and imageProcess
function started to run in worker thread.
Also, frame passed to m_videoSink in order to show the frames on the screen.
m_videoSink->setVideoFrame(frame);
SBarcodeFilter
is a class that you need to use for scanning case. By default it scans only specific basic formats of code (Code 39, Code 93, Code 128, QR Code and DataMatrix.).
The goal of that is to limit number of possible formats and improve performance.
To specify formats that should be accepted by the SBarcodeFilter
instance, you need to set it's format
property accordingly. This property allows setting multiple enum values as it's for flags. Add the following to your SBarcodeFilter
item in Qml code:
Component.onCompleted: {
barcodeFilter.format = SCodes.OneDCodes
}
See the enumeration values that represent supported formats in SBarcodeFormat.h
To accept all supported formats use SCodes.Any
.
Both build systems have their examples located in same directory. All you need to do is to just open proper file(CMakeLists.txt or *.pro file) for different build system to be used.
PROJECT | BUILD SYSTEM | WINDOWS-MinGW | WINDOWS-MSVC | LINUX-GCC | ANDROID |
---|---|---|---|---|---|
QmlBarcodeReader | qmake | ✔️ | ✔️ | ✔️ | ✔️ |
QmlBarcodeGenerator | qmake | ✔️ | ✔️ | ✔️ | ✔️ |
QmlBarcodeReader | CMake | ❌ | ✔️ | ✔️ | ✔️ |
QmlBarcodeGenerator | CMake | ❌ | ✔️ | ✔️ | ✔️ |
PROJECT | BUILD SYSTEM | WINDOWS-MinGW | WINDOWS-MSVC | LINUX-GCC | ANDROID |
---|---|---|---|---|---|
QmlBarcodeReader | qmake | ✔️ | ✔️ | ✔️ | ✔️ |
QmlBarcodeGenerator | qmake | ✔️ | ✔️ | ✔️ | ✔️ |
QmlBarcodeReader | CMake | ✔️ | ✔️ | ✔️ | ✔️ |
QmlBarcodeGenerator | CMake | ✔️ | ✔️ | ✔️ | ✔️ |
Please ensure that proper Java & NDK version installed on your system. This examples tested w/ Java 11 and 22.1.7171670 Android NDK version.
SCodes project was developed and is maintained mainly by Scythe Studio company. We are an official Qt Service Partner and a provider of Qt Software Development services including:
- Desktop applications development
- Mobile applications development
- Embedded systems development
- Qt and C++ consulting
- UI/UX designing
Do not hesitate visiting https://scythe-studio.com to discover our capabilities and learn more about Qt Software Development from Scythe Studio Blog.