Skip to content

Commit

Permalink
Merge pull request #212 from ftylitak/qt6_2_multimedia_support
Browse files Browse the repository at this point in the history
Qt 6.2 multimedia support
  • Loading branch information
ftylitak authored Dec 26, 2021
2 parents 2fd4dd6 + ebb3e5e commit 6ea2b31
Show file tree
Hide file tree
Showing 14 changed files with 474 additions and 90 deletions.
97 changes: 47 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,41 @@ Qt/QML wrapper library for the [ZXing](https://github.com/zxing/zxing) barcode i

Supports barcode decoding for the following types:

- UPC-A
- UPC-E
- EAN-8
- EAN-13
- ITF
- Code 39
- Code 93
- Code 128 (GS1)
- Codabar
- QR Code
- Data Matrix
- Aztec (beta)
- PDF 417
- UPC-A
- UPC-E
- EAN-8
- EAN-13
- ITF
- Code 39
- Code 93
- Code 128 (GS1)
- Codabar
- QR Code
- Data Matrix
- Aztec (beta)
- PDF 417

Supports barcode encoding for the following types:

- QR Code
- 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)
1. [Control dependencies](#controlDependencies)
1. [QZXing (core)](#controlDependenciesCore)
1. [QZXing (core + QML)](#controlDependenciesCoreQML)
1. [QZXing + QZXingFilter](#controlDependenciesCoreQMLQZXingFilter)
1. [Embed the source code](#embedInSourceCode)
1. [Compile the project as an external library](#externalLibrary)
1. [Control dependencies](#controlDependencies)
1. [QZXing (core)](#controlDependenciesCore)
1. [QZXing (core + QML)](#controlDependenciesCoreQML)
1. [QZXing + QZXingFilter](#controlDependenciesCoreQMLQZXingFilter)
1. [How to use](#howTo)
1. [Decoding operation](#howToDecoding)
1. [C++/Qt](#howToDecodingCPP)
1. [Qt Quick](#howToDecodingQtQuick)
1. [Encoding operation](#howToEncoding)
1. [C++/Qt](#howToEncodingCPP)
1. [Qt Quick](#howToEncodingQtQuick)
1. [Encoded text format Information](#howToEncodingFormatExamples)
1. [Decoding operation](#howToDecoding)
1. [C++/Qt](#howToDecodingCPP)
1. [Qt Quick](#howToDecodingQtQuick)
1. [Encoding operation](#howToEncoding)
1. [C++/Qt](#howToEncodingCPP)
1. [Qt Quick](#howToEncodingQtQuick)
1. [Encoded text format Information](#howToEncodingFormatExamples)
1. [Unit test dependency](#unitTestDependency)
1. [Qt 6 limitations](#qt6limitations)
1. [Contact](#contact)
Expand Down Expand Up @@ -98,18 +98,22 @@ CONFIG += qzxing_qml

### QZXing + QZXingFilter

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.
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:
QZXing includes QZXingFilter, an implementation to provide live feed to the decoding library. It automatically includes QML implementation as well.
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:

```qmake
CONFIG += qzxing_multimedia
```

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).

(Pending task: a wiki page should be written to better explain the usage of the QZXingFilter component)

<a name="howTo"></a>

# How to use

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).
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).

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

Expand Down Expand Up @@ -159,7 +163,7 @@ int main()
The in the QML file

```qml
import QZXing 3.2
import QZXing 3.3
function decode(preview) {
imageToDecode.source = preview
Expand Down Expand Up @@ -210,9 +214,9 @@ The encoding function has been written as static as it does not have any depende

Use the encoding function with its default settings:

- Format: QR Code
- Size: 240x240
- Error Correction Level: Low (L)
- Format: QR Code
- Size: 240x240
- Error Correction Level: Low (L)

```cpp
#include "QZXing.h"
Expand Down Expand Up @@ -250,7 +254,7 @@ QZXing::registerQMLImageProvider(engine);
Default settings:

```qml
import QZXing 3.2
import QZXing 3.3
TextField {
id: inputField
Expand All @@ -265,18 +269,18 @@ Image{

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

| attribute name | value | description |
| --------------- | ----------- | --------------------------------------------------------- |
| border | true, false | image has border (white 1px) |
| correctionLevel | L, M, Q, H | the error correction level |
| format | qrcode | the encode formatter. Currently only QR Code. |
| transparent | true, false | whether the black pixels are transparent |
| explicitSize | int | if provided, it will be the size of the Qr rectangle |
| attribute name | value | description |
| --------------- | ----------- | ---------------------------------------------------- |
| border | true, false | image has border (white 1px) |
| correctionLevel | L, M, Q, H | the error correction level |
| format | qrcode | the encode formatter. Currently only QR Code. |
| transparent | true, false | whether the black pixels are transparent |
| explicitSize | int | if provided, it will be the size of the Qr rectangle |

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

```qml
import QZXing 3.2
import QZXing 3.3
TextField {
id: inputField
Expand Down Expand Up @@ -324,13 +328,6 @@ After testing, it seems that QTextCodec, if used through core5compat in Qt 6, it
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.
If QZXing if build for Qt 5, QTextCodec is used as it was.

## Multimedia (Video / Camera)

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.
To my knowledge, there is no specific replacement for this absent modules and I hope they get re-supported for Qt 6.

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).

<a name="contact"></a>

# Contact
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import DropArea 1.0
import QZXing 3.2
import QZXing 3.3

Rectangle {
width: 360
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import QtQuick 2.0
import QZXing 3.2
import QZXing 3.3

Rectangle {
width: 360
Expand Down
53 changes: 29 additions & 24 deletions examples/QZXingLive/QZXingLive.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ CONFIG(debug, debug|release) {
}

HEADERS += \
application.h \
native.h
application.h

SOURCES += main.cpp \
application.cpp \
native.cpp
application.cpp

RESOURCES += qml.qrc

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

android {
QT += androidextras

DISTFILES += \
android/AndroidManifest.xml \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradlew \
android/res/values/libs.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat \
android/AndroidManifest.xml \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradlew \
android/res/values/libs.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat

ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
lessThan(QT_VERSION, 6.2) {
HEADERS += \
native.h

SOURCES += \
native.cpp

QT += androidextras

DISTFILES += \
android/AndroidManifest.xml \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradlew \
android/res/values/libs.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat \
android/AndroidManifest.xml \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradlew \
android/res/values/libs.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat

ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
}
}

else:ios {
QMAKE_INFO_PLIST=Info.plist
}

22 changes: 21 additions & 1 deletion examples/QZXingLive/application.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#include "application.h"
#include <QDebug>

#if QT_VERSION < 0x060000
#include "native.h"
#endif


#if defined(Q_OS_ANDROID)

#if QT_VERSION < 0x060100
#include <QAndroidJniObject>
#include <QtAndroid>
#else
#include <QJniObject>
#endif

#endif // Q_OS_ANDROID

Application::Application()
Expand All @@ -18,12 +28,18 @@ Application::Application()
connect(this, &Application::onPermissionsDenied,
this, &Application::initializeQML);

NativeHelpers::registerApplicationInstance(this);
#if QT_VERSION < 0x060000
NativeHelpers::registerApplicationInstance(this);
#endif
}

void Application::initializeQML()
{
#if QT_VERSION < 0x060200
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
#else
engine.load(QUrl(QStringLiteral("qrc:/main_qt6_2.qml")));
#endif // QT_VERSION < 0x060200
}

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

#if QT_VERSION < 0x060000
QAndroidJniObject::callStaticMethod<void>("org/ftylitak/qzxing/Utilities",
"requestQZXingPermissions",
"(Landroid/app/Activity;)V",
QtAndroid::androidActivity().object());
#else
emit onPermissionsGranted();
#endif
qDebug() << "Permissions granted";
#else
emit onPermissionsGranted();
Expand Down
2 changes: 1 addition & 1 deletion examples/QZXingLive/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import QtQuick.Controls 2.0
import QtQuick.Layouts 1.1
import QtMultimedia 5.5

import QZXing 3.2
import QZXing 3.3

ApplicationWindow
{
Expand Down
Loading

0 comments on commit 6ea2b31

Please sign in to comment.