Skip to content

Commit 6ea2b31

Browse files
authored
Merge pull request #212 from ftylitak/qt6_2_multimedia_support
Qt 6.2 multimedia support
2 parents 2fd4dd6 + ebb3e5e commit 6ea2b31

File tree

14 files changed

+474
-90
lines changed

14 files changed

+474
-90
lines changed

README.md

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,41 @@ Qt/QML wrapper library for the [ZXing](https://github.com/zxing/zxing) barcode i
44

55
Supports barcode decoding for the following types:
66

7-
- UPC-A
8-
- UPC-E
9-
- EAN-8
10-
- EAN-13
11-
- ITF
12-
- Code 39
13-
- Code 93
14-
- Code 128 (GS1)
15-
- Codabar
16-
- QR Code
17-
- Data Matrix
18-
- Aztec (beta)
19-
- PDF 417
7+
- UPC-A
8+
- UPC-E
9+
- EAN-8
10+
- EAN-13
11+
- ITF
12+
- Code 39
13+
- Code 93
14+
- Code 128 (GS1)
15+
- Codabar
16+
- QR Code
17+
- Data Matrix
18+
- Aztec (beta)
19+
- PDF 417
2020

2121
Supports barcode encoding for the following types:
2222

23-
- QR Code
23+
- QR Code
2424

2525
# Table of contents
2626

2727
1. [How to include](#howToInclude)
28-
1. [Embed the source code](#embedInSourceCode)
29-
1. [Compile the project as an external library](#externalLibrary)
30-
1. [Control dependencies](#controlDependencies)
31-
1. [QZXing (core)](#controlDependenciesCore)
32-
1. [QZXing (core + QML)](#controlDependenciesCoreQML)
33-
1. [QZXing + QZXingFilter](#controlDependenciesCoreQMLQZXingFilter)
28+
1. [Embed the source code](#embedInSourceCode)
29+
1. [Compile the project as an external library](#externalLibrary)
30+
1. [Control dependencies](#controlDependencies)
31+
1. [QZXing (core)](#controlDependenciesCore)
32+
1. [QZXing (core + QML)](#controlDependenciesCoreQML)
33+
1. [QZXing + QZXingFilter](#controlDependenciesCoreQMLQZXingFilter)
3434
1. [How to use](#howTo)
35-
1. [Decoding operation](#howToDecoding)
36-
1. [C++/Qt](#howToDecodingCPP)
37-
1. [Qt Quick](#howToDecodingQtQuick)
38-
1. [Encoding operation](#howToEncoding)
39-
1. [C++/Qt](#howToEncodingCPP)
40-
1. [Qt Quick](#howToEncodingQtQuick)
41-
1. [Encoded text format Information](#howToEncodingFormatExamples)
35+
1. [Decoding operation](#howToDecoding)
36+
1. [C++/Qt](#howToDecodingCPP)
37+
1. [Qt Quick](#howToDecodingQtQuick)
38+
1. [Encoding operation](#howToEncoding)
39+
1. [C++/Qt](#howToEncodingCPP)
40+
1. [Qt Quick](#howToEncodingQtQuick)
41+
1. [Encoded text format Information](#howToEncodingFormatExamples)
4242
1. [Unit test dependency](#unitTestDependency)
4343
1. [Qt 6 limitations](#qt6limitations)
4444
1. [Contact](#contact)
@@ -98,18 +98,22 @@ CONFIG += qzxing_qml
9898

9999
### QZXing + QZXingFilter
100100

101-
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.
102-
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:
101+
QZXing includes QZXingFilter, an implementation to provide live feed to the decoding library. It automatically includes QML implementation as well.
102+
This option requires "multimedia" Qt module this is why it is considered as a separate configuration. It can be used by adding the following line to the .pro file of a project:
103103

104104
```qmake
105105
CONFIG += qzxing_multimedia
106106
```
107107

108+
For examples on how to use QZXingFilter, it is advised to see [QZXingLive](https://github.com/ftylitak/qzxing/tree/master/examples/QZXingLive) example project. For Qt 5.x versions check [main.qml](https://github.com/ftylitak/qzxing/tree/master/examples/QZXingLive/main.qml) file, whereas for Qt 6.2 (or newer) check [main_qt6_2.qml](https://github.com/ftylitak/qzxing/tree/master/examples/QZXingLive/main_qt6_2.qml).
109+
110+
(Pending task: a wiki page should be written to better explain the usage of the QZXingFilter component)
111+
108112
<a name="howTo"></a>
109113

110114
# How to use
111115

112-
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).
116+
Follows simple code snippets that briefly 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).
113117

114118
<a name="howToDecoding"></a>
115119

@@ -159,7 +163,7 @@ int main()
159163
The in the QML file
160164

161165
```qml
162-
import QZXing 3.2
166+
import QZXing 3.3
163167
164168
function decode(preview) {
165169
imageToDecode.source = preview
@@ -210,9 +214,9 @@ The encoding function has been written as static as it does not have any depende
210214

211215
Use the encoding function with its default settings:
212216

213-
- Format: QR Code
214-
- Size: 240x240
215-
- Error Correction Level: Low (L)
217+
- Format: QR Code
218+
- Size: 240x240
219+
- Error Correction Level: Low (L)
216220

217221
```cpp
218222
#include "QZXing.h"
@@ -250,7 +254,7 @@ QZXing::registerQMLImageProvider(engine);
250254
Default settings:
251255

252256
```qml
253-
import QZXing 3.2
257+
import QZXing 3.3
254258
255259
TextField {
256260
id: inputField
@@ -265,18 +269,18 @@ Image{
265269

266270
Or use the encoding function with the optional custom settings that are passed like URL query parameters:
267271

268-
| attribute name | value | description |
269-
| --------------- | ----------- | --------------------------------------------------------- |
270-
| border | true, false | image has border (white 1px) |
271-
| correctionLevel | L, M, Q, H | the error correction level |
272-
| format | qrcode | the encode formatter. Currently only QR Code. |
273-
| transparent | true, false | whether the black pixels are transparent |
274-
| explicitSize | int | if provided, it will be the size of the Qr rectangle |
272+
| attribute name | value | description |
273+
| --------------- | ----------- | ---------------------------------------------------- |
274+
| border | true, false | image has border (white 1px) |
275+
| correctionLevel | L, M, Q, H | the error correction level |
276+
| format | qrcode | the encode formatter. Currently only QR Code. |
277+
| transparent | true, false | whether the black pixels are transparent |
278+
| explicitSize | int | if provided, it will be the size of the Qr rectangle |
275279

276280
the size of the image can be adjusted by using the Image.sourceWidth and Image.sourceHeight properties of Image QML element.
277281

278282
```qml
279-
import QZXing 3.2
283+
import QZXing 3.3
280284
281285
TextField {
282286
id: inputField
@@ -324,13 +328,6 @@ After testing, it seems that QTextCodec, if used through core5compat in Qt 6, it
324328
To avoid the dependency of an extra module (that also does not work as supposed to), QTextCodec has been replaced by [QStringDecoder](https://doc.qt.io/qt-6/qstringdecoder.html) only when building for Qt 6.
325329
If QZXing if build for Qt 5, QTextCodec is used as it was.
326330

327-
## Multimedia (Video / Camera)
328-
329-
Qt Multimedia modules that includes the Camera item for QML and Video related operations for frame manipulation and live decoding are not supported in Qt 6 for the moment.
330-
To my knowledge, there is no specific replacement for this absent modules and I hope they get re-supported for Qt 6.
331-
332-
Thus, if building for Qt 5, everything works fine. If trying to used **qzxing_multimedia** configuration in your **pro** file, the project will fail (example: [QZXingLive](https://github.com/ftylitak/qzxing/tree/master/examples/QZXingLive) project).
333-
334331
<a name="contact"></a>
335332

336333
# Contact

examples/QZXingDragNDropTest/qml/QZXingDragNDropTest/main_QtQuick1.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
22
import QtQuick 1.1
33
import DropArea 1.0
4-
import QZXing 3.2
4+
import QZXing 3.3
55

66
Rectangle {
77
width: 360

examples/QZXingDragNDropTest/qml/QZXingDragNDropTest/main_QtQuick2.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import QtQuick 2.0
2-
import QZXing 3.2
2+
import QZXing 3.3
33

44
Rectangle {
55
width: 360

examples/QZXingLive/QZXingLive.pro

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ CONFIG(debug, debug|release) {
1515
}
1616

1717
HEADERS += \
18-
application.h \
19-
native.h
18+
application.h
2019

2120
SOURCES += main.cpp \
22-
application.cpp \
23-
native.cpp
21+
application.cpp
2422

2523
RESOURCES += qml.qrc
2624

@@ -33,28 +31,35 @@ include(../../src/QZXing-components.pri)
3331
include(deployment.pri)
3432

3533
android {
36-
QT += androidextras
37-
38-
DISTFILES += \
39-
android/AndroidManifest.xml \
40-
android/gradle/wrapper/gradle-wrapper.jar \
41-
android/gradlew \
42-
android/res/values/libs.xml \
43-
android/build.gradle \
44-
android/gradle/wrapper/gradle-wrapper.properties \
45-
android/gradlew.bat \
46-
android/AndroidManifest.xml \
47-
android/gradle/wrapper/gradle-wrapper.jar \
48-
android/gradlew \
49-
android/res/values/libs.xml \
50-
android/build.gradle \
51-
android/gradle/wrapper/gradle-wrapper.properties \
52-
android/gradlew.bat
53-
54-
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
34+
lessThan(QT_VERSION, 6.2) {
35+
HEADERS += \
36+
native.h
37+
38+
SOURCES += \
39+
native.cpp
40+
41+
QT += androidextras
42+
43+
DISTFILES += \
44+
android/AndroidManifest.xml \
45+
android/gradle/wrapper/gradle-wrapper.jar \
46+
android/gradlew \
47+
android/res/values/libs.xml \
48+
android/build.gradle \
49+
android/gradle/wrapper/gradle-wrapper.properties \
50+
android/gradlew.bat \
51+
android/AndroidManifest.xml \
52+
android/gradle/wrapper/gradle-wrapper.jar \
53+
android/gradlew \
54+
android/res/values/libs.xml \
55+
android/build.gradle \
56+
android/gradle/wrapper/gradle-wrapper.properties \
57+
android/gradlew.bat
58+
59+
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
60+
}
5561
}
5662

5763
else:ios {
5864
QMAKE_INFO_PLIST=Info.plist
5965
}
60-

examples/QZXingLive/application.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
#include "application.h"
22
#include <QDebug>
3+
4+
#if QT_VERSION < 0x060000
35
#include "native.h"
6+
#endif
7+
48

59
#if defined(Q_OS_ANDROID)
10+
11+
#if QT_VERSION < 0x060100
612
#include <QAndroidJniObject>
713
#include <QtAndroid>
14+
#else
15+
#include <QJniObject>
16+
#endif
17+
818
#endif // Q_OS_ANDROID
919

1020
Application::Application()
@@ -18,12 +28,18 @@ Application::Application()
1828
connect(this, &Application::onPermissionsDenied,
1929
this, &Application::initializeQML);
2030

21-
NativeHelpers::registerApplicationInstance(this);
31+
#if QT_VERSION < 0x060000
32+
NativeHelpers::registerApplicationInstance(this);
33+
#endif
2234
}
2335

2436
void Application::initializeQML()
2537
{
38+
#if QT_VERSION < 0x060200
2639
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
40+
#else
41+
engine.load(QUrl(QStringLiteral("qrc:/main_qt6_2.qml")));
42+
#endif // QT_VERSION < 0x060200
2743
}
2844

2945
void Application::checkPermissions()
@@ -32,10 +48,14 @@ void Application::checkPermissions()
3248
//intentionally called in the C++ thread since it is blocking and will continue after the check
3349
qDebug() << "About to request permissions";
3450

51+
#if QT_VERSION < 0x060000
3552
QAndroidJniObject::callStaticMethod<void>("org/ftylitak/qzxing/Utilities",
3653
"requestQZXingPermissions",
3754
"(Landroid/app/Activity;)V",
3855
QtAndroid::androidActivity().object());
56+
#else
57+
emit onPermissionsGranted();
58+
#endif
3959
qDebug() << "Permissions granted";
4060
#else
4161
emit onPermissionsGranted();

examples/QZXingLive/main.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import QtQuick.Controls 2.0
44
import QtQuick.Layouts 1.1
55
import QtMultimedia 5.5
66

7-
import QZXing 3.2
7+
import QZXing 3.3
88

99
ApplicationWindow
1010
{

0 commit comments

Comments
 (0)