Support Qt 6

changed QTimer to QElapsedTimer
used QStringDecoder instead of QTextCodec if building for Qt 6
This commit is contained in:
Nikolaos Ftylitakis 2021-01-26 11:11:17 +02:00
parent 63850d5f03
commit 08a75a8e32
3 changed files with 24 additions and 12 deletions

View File

@ -3,7 +3,7 @@
#include <QPainter> #include <QPainter>
#include <QDebug> #include <QDebug>
#include <QThread> #include <QThread>
#include <QTime> #include <QElapsedTimer>
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
#include <QGraphicsObject> #include <QGraphicsObject>
@ -33,7 +33,7 @@ QImage ImageHandler::extractQImage(QObject *imageObj, int offsetX, int offsetY,
return QImage(); return QImage();
} }
QTime timer; QElapsedTimer timer;
timer.start(); timer.start();
QSharedPointer<QQuickItemGrabResult> result = item->grabToImage(); QSharedPointer<QQuickItemGrabResult> result = item->grabToImage();
if (result) { if (result) {

View File

@ -14,7 +14,11 @@
#include <QUrl> #include <QUrl>
#include <QFileInfo> #include <QFileInfo>
#include <QColor> #include <QColor>
#include <QtCore/QTextCodec> #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtCore/QTextCodec>
#else
#include <QStringDecoder>
#endif
#include <QDebug> #include <QDebug>
#ifdef ENABLE_ENCODER_QR_CODE #ifdef ENABLE_ENCODER_QR_CODE
@ -223,7 +227,7 @@ QString QZXing::decoderFormatToString(int fmt)
QString QZXing::foundedFormat() const QString QZXing::foundedFormat() const
{ {
return foundedFmt; return decodedFormat;
} }
QString QZXing::charSet() const 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()); QString string = QString(res->getText()->getText().c_str());
if (!string.isEmpty() && (string.length() > 0)) { if (!string.isEmpty() && (string.length() > 0)) {
int fmt = res->getBarcodeFormat().value; int fmt = res->getBarcodeFormat().value;
foundedFmt = decoderFormatToString(1<<fmt); decodedFormat = decoderFormatToString(1<<fmt);
charSet_ = QString::fromStdString(res->getCharSet()); charSet_ = QString::fromStdString(res->getCharSet());
qDebug() << "charSet_: " << charSet_;
if (!charSet_.isEmpty()) { if (!charSet_.isEmpty()) {
QTextCodec *codec = QTextCodec::codecForName(res->getCharSet().c_str()); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (codec) QTextCodec *codec = QTextCodec::codecForName(res->getCharSet().c_str());
string = codec->toUnicode(res->getText()->getText().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 tagFound(string);
emit tagFoundAdvanced(string, foundedFmt, charSet_); emit tagFoundAdvanced(string, decodedFormat, charSet_);
QVariantMap metadataMap = metadataToMap(res->getMetadata()); QVariantMap metadataMap = metadataToMap(res->getMetadata());
emit tagFoundAdvanced(string, foundedFmt, charSet_, metadataMap); emit tagFoundAdvanced(string, decodedFormat, charSet_, metadataMap);
try { try {
const QRectF rect = getTagRect(res->getResultPoints(), binz->getBlackMatrix()); const QRectF rect = getTagRect(res->getResultPoints(), binz->getBlackMatrix());
emit tagFoundAdvanced(string, foundedFmt, charSet_, rect); emit tagFoundAdvanced(string, decodedFormat, charSet_, rect);
}catch(zxing::Exception &/*e*/){} }catch(zxing::Exception &/*e*/){}
} }
emit decodingFinished(true); emit decodingFinished(true);

View File

@ -254,7 +254,7 @@ private:
SourceFilterType imageSourceFilter; SourceFilterType imageSourceFilter;
ImageHandler *imageHandler; ImageHandler *imageHandler;
int processingTime; int processingTime;
QString foundedFmt; QString decodedFormat;
QString charSet_; QString charSet_;
bool tryHarder_; bool tryHarder_;
bool lastDecodeOperationSucceded_; bool lastDecodeOperationSucceded_;