Skip to content
Snippets Groups Projects
Verified Commit d7f6151c authored by Burak Hançerli's avatar Burak Hançerli :headphones:
Browse files

fix: QDS-11873 laggy QR scanner

parent a8187df3
No related branches found
No related tags found
1 merge request!33Spyrosoft Feedbacks
Pipeline #66985 passed
......@@ -13,13 +13,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(
QT NAMES Qt6
COMPONENTS Core
COMPONENTS Core Widgets Quick Gui Qml Multimedia MultimediaWidgets Concurrent
REQUIRED
)
find_package(
Qt6
COMPONENTS Core Widgets Quick Gui Qml Multimedia MultimediaWidgets
COMPONENTS Core Widgets Quick Gui Qml Multimedia MultimediaWidgets Concurrent
REQUIRED
)
......@@ -44,9 +44,11 @@ qt_add_executable(${PROJECT_NAME}
)
target_link_libraries(${PROJECT_NAME} PRIVATE
Qt::Core Qt::Widgets
Qt::Quick Qt::Gui
Qt::Qml Qt::GuiPrivate Qt::Multimedia Qt::MultimediaWidgets
Qt6::Core Qt6::Widgets
Qt6::Quick Qt6::Gui
Qt6::Qml Qt6::GuiPrivate
Qt6::Multimedia Qt6::MultimediaWidgets
Qt6::Concurrent
ZXing::ZXing
)
......
......@@ -28,6 +28,7 @@
#include <QCameraDevice>
#include <QDesktopServices>
#include <QElapsedTimer>
#include <QFileInfo>
#include <QJsonArray>
#include <QJsonObject>
......@@ -37,6 +38,7 @@
#include <QSettings>
#include <QSslSocket>
#include <QVideoSink>
#include <QtConcurrent>
#include "../3rdparty/zxing-cpp/example/ZXingQtReader.h"
......@@ -217,20 +219,47 @@ void Backend::openCamera()
this,
[&](const QVideoFrame &frame) {
static int i = 0;
if (i++ < 30) {
static QAtomicInt running = 0;
if (i++ < 20 || running > 0) {
return;
}
i = 0;
auto results = ReadBarcodes(frame.toImage());
for (auto &result : results) {
QtConcurrent::run([=] {
// lock the thread so that only one barcode can be read at a time
running++;
QElapsedTimer timer;
timer.start();
QList<Result> results = ReadBarcodes(frame.toImage());
qDebug() << "Barcode detection took" << timer.elapsed() << "ms";
// release the lock so that another barcode can be read
running--;
return results;
}).then([=](const QList<Result> &results) {
if (results.isEmpty() || !m_captureSession)
return;
qDebug() << "Stopping camera";
qobject_cast<CustomVideoWidget *>(m_captureSession->videoOutput())->close();
qDebug() << "Camera stopped";
Result result = results.first();
qDebug() << "Text: " << result.text();
qDebug() << "Format: " << result.format();
qDebug() << "Content:" << result.contentType();
parseDesignViewerUrl(result.text());
qobject_cast<CustomVideoWidget *>(m_captureSession->videoOutput())->close();
}
// we have to use invokeMethod because we are in a different thread
// then where the serviceConnector is created
QMetaObject::invokeMethod(this,
"parseDesignViewerUrl",
Qt::QueuedConnection,
Q_ARG(QUrl, result.text()));
});
});
// stop camera when app is not active.
......@@ -469,7 +498,7 @@ void Backend::updateUserProjectList()
return;
}
qDebug() << "Fetching available project list for user: " << userHash;
qDebug() << "Fetching available project list for user:" << userHash;
QJsonArray projectList = m_serviceConnector.fetchUserProjectList(userHash);
if (projectList.isEmpty()) {
......
......@@ -53,13 +53,13 @@ QByteArray ServiceConnector::fetchResource(const QString &url, const bool quite)
QObject::connect(reply.data(),
&QNetworkReply::downloadProgress,
this,
[&](qint64 bytesReceived, qint64 bytesTotal)
{
float percentage = roundf((float)bytesReceived / (float)bytesTotal * 100);
qDebug() << "Download progress" << QString::number(percentage) << "% -" << QString::number(bytesReceived) << "/" << QString::number(bytesTotal);
[&](qint64 bytesReceived, qint64 bytesTotal) {
float percentage = roundf((float) bytesReceived / (float) bytesTotal * 100);
qDebug() << "Download progress" << QString::number(percentage) << "% -"
<< QString::number(bytesReceived) << "/"
<< QString::number(bytesTotal);
emit downloadProgress(percentage);
});
loop.exec();
if (reply->error() != QNetworkReply::NoError) {
......@@ -98,6 +98,7 @@ QJsonArray ServiceConnector::fetchUserProjectList(const QString &userHash)
auto reply = fetchResource("https://designviewer.qt.io/api/v1/qmlrc/list/" + userHash
+ "?key=818815",
true);
if (reply.size() == 0) {
return QJsonArray();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment