From 08a75a8e32352dd213a3e9bf29c0c5d7ac653012 Mon Sep 17 00:00:00 2001 From: Nikolaos Ftylitakis Date: Tue, 26 Jan 2021 11:11:17 +0200 Subject: [PATCH] Support Qt 6 changed QTimer to QElapsedTimer used QStringDecoder instead of QTextCodec if building for Qt 6 --- src/ImageHandler.cpp | 4 ++-- src/QZXing.cpp | 30 +++++++++++++++++++++--------- src/QZXing.h | 2 +- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/ImageHandler.cpp b/src/ImageHandler.cpp index a0c0ce2..e7b5a4f 100644 --- a/src/ImageHandler.cpp +++ b/src/ImageHandler.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #if QT_VERSION < 0x050000 #include @@ -33,7 +33,7 @@ QImage ImageHandler::extractQImage(QObject *imageObj, int offsetX, int offsetY, return QImage(); } - QTime timer; + QElapsedTimer timer; timer.start(); QSharedPointer result = item->grabToImage(); if (result) { diff --git a/src/QZXing.cpp b/src/QZXing.cpp index 677c78d..f0255d4 100644 --- a/src/QZXing.cpp +++ b/src/QZXing.cpp @@ -14,7 +14,11 @@ #include #include #include -#include +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + #include +#else + #include +#endif #include #ifdef ENABLE_ENCODER_QR_CODE @@ -223,7 +227,7 @@ QString QZXing::decoderFormatToString(int fmt) QString QZXing::foundedFormat() const { - return foundedFmt; + return decodedFormat; } QString QZXing::charSet() const @@ -521,23 +525,31 @@ QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bo QString string = QString(res->getText()->getText().c_str()); if (!string.isEmpty() && (string.length() > 0)) { int fmt = res->getBarcodeFormat().value; - foundedFmt = decoderFormatToString(1<getCharSet()); + qDebug() << "charSet_: " << charSet_; if (!charSet_.isEmpty()) { - QTextCodec *codec = QTextCodec::codecForName(res->getCharSet().c_str()); - if (codec) - string = codec->toUnicode(res->getText()->getText().c_str()); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QTextCodec *codec = QTextCodec::codecForName(res->getCharSet().c_str()); + if (codec) + string = codec->toUnicode(res->getText()->getText().c_str()); +#else + QStringDecoder decoder(res->getCharSet().c_str()); + if(decoder.isValid()) { + string = decoder.decode(QByteArray(res->getText()->getText().c_str())); + } +#endif } emit tagFound(string); - emit tagFoundAdvanced(string, foundedFmt, charSet_); + emit tagFoundAdvanced(string, decodedFormat, charSet_); QVariantMap metadataMap = metadataToMap(res->getMetadata()); - emit tagFoundAdvanced(string, foundedFmt, charSet_, metadataMap); + emit tagFoundAdvanced(string, decodedFormat, charSet_, metadataMap); try { const QRectF rect = getTagRect(res->getResultPoints(), binz->getBlackMatrix()); - emit tagFoundAdvanced(string, foundedFmt, charSet_, rect); + emit tagFoundAdvanced(string, decodedFormat, charSet_, rect); }catch(zxing::Exception &/*e*/){} } emit decodingFinished(true); diff --git a/src/QZXing.h b/src/QZXing.h index 5fa8366..2a5c046 100644 --- a/src/QZXing.h +++ b/src/QZXing.h @@ -254,7 +254,7 @@ private: SourceFilterType imageSourceFilter; ImageHandler *imageHandler; int processingTime; - QString foundedFmt; + QString decodedFormat; QString charSet_; bool tryHarder_; bool lastDecodeOperationSucceded_;