aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2024-04-17 13:08:10 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-04-17 19:43:19 +0000
commit3a15c0ad74b7c2498dc312b873d62de460d9d92d (patch)
treed242c3370e200e95f035cd0eb1bba52e0eea4e59
parent8b2a4913c3c7a6e5c84e4cff567ccfde1c5922a0 (diff)
Modernize QML SceneGrabber
Use PMF syntax for signal/slot connections, and categorized logging rather than preprocessor defines for diagnostics. Add more and fix some debug output. Change-Id: I388904fd0caa474bff137b59358489e962ccf955 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io> (cherry picked from commit 82f6e4c3f7efe7c1bef1b389fafc812de00d466a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tests/baseline/scenegraph/scenegrabber/main.cpp38
1 files changed, 18 insertions, 20 deletions
diff --git a/tests/baseline/scenegraph/scenegrabber/main.cpp b/tests/baseline/scenegraph/scenegrabber/main.cpp
index f830b2a3a4..046c535e24 100644
--- a/tests/baseline/scenegraph/scenegrabber/main.cpp
+++ b/tests/baseline/scenegraph/scenegrabber/main.cpp
@@ -7,6 +7,7 @@
#include <QtCore/QHashFunctions>
#include <QtGui/QGuiApplication>
#include <QtGui/QImage>
+#include <QtCore/QLoggingCategory>
#include <QtQuick/QQuickView>
#include <QtQuick/QQuickItem>
@@ -29,6 +30,7 @@
#define SCENE_TIMEOUT 6000
//#define GRABBERDEBUG
+Q_LOGGING_CATEGORY(lcGrabber, "qt.baseline.scenegrabber")
static const QSize DefaultGrabSize(320, 480);
@@ -45,15 +47,17 @@ public:
grabTimer = new QTimer(this);
grabTimer->setSingleShot(true);
grabTimer->setInterval(SCENE_STABLE_TIME);
- connect(grabTimer, SIGNAL(timeout()), SLOT(grab()));
+ connect(grabTimer, &QTimer::timeout, this, &GrabbingView::grab);
if (!preferAppWindow)
QObject::connect(this, &QQuickWindow::afterRendering, this, &GrabbingView::startGrabbing);
- QTimer::singleShot(SCENE_TIMEOUT, this, SLOT(timedOut()));
+ QTimer::singleShot(SCENE_TIMEOUT, this, &GrabbingView::timedOut);
}
void setApplicationWindow(QWindow* window) {
+ qCDebug(lcGrabber) << "Using ApplicationWindow as visual parent" << this;
+
appwindow = qobject_cast<QQuickApplicationWindow *>(window);
if (preferAppWindow)
QObject::connect(this, &QQuickWindow::afterRendering, this, &GrabbingView::startGrabbing);
@@ -63,6 +67,7 @@ public:
private slots:
void startGrabbing()
{
+ qCDebug(lcGrabber) << "Starting to grab";
if (!initDone) {
initDone = true;
grabTimer->start();
@@ -71,13 +76,15 @@ private slots:
void grab()
{
- if (isGrabbing)
+ if (isGrabbing) {
+ qCDebug(lcGrabber) << "Already grabbing, skipping";
return;
- isGrabbing = true;
+ }
+
+ QScopedValueRollback grabGuard(isGrabbing, true);
+
grabNo++;
-#ifdef GRABBERDEBUG
- printf("grab no. %i\n", grabNo);
-#endif
+ qCDebug(lcGrabber) << "grab no." << grabNo;
QImage img;
img = appwindow ? appwindow->grabWindow() : grabWindow();
if (!img.isNull() && img == lastGrab) {
@@ -86,15 +93,11 @@ private slots:
lastGrab = img;
grabTimer->start();
}
-
- isGrabbing = false;
}
void sceneStabilized()
{
-#ifdef GRABBERDEBUG
- printf("...sceneStabilized IN\n");
-#endif
+ qCDebug(lcGrabber) << "...sceneStabilized IN";
if (QGuiApplication::platformName() == QLatin1String("eglfs")) {
QSize grabSize = initialSize().isEmpty() ? DefaultGrabSize : initialSize();
lastGrab = lastGrab.copy(QRect(QPoint(0, 0), grabSize));
@@ -119,9 +122,7 @@ private slots:
}
}
QGuiApplication::exit(0);
-#ifdef GRABBERDEBUG
- printf("...sceneStabilized OUT\n");
-#endif
+ qCDebug(lcGrabber) << "...sceneStabilized OUT";
}
void timedOut()
@@ -181,7 +182,6 @@ int main(int argc, char *argv[])
}
}
else if (arg == "-useAppWindow") {
- qWarning() << "Using ApplicationWindow as visual parent";
useAppWindow = true;
}
else if (ifile.isEmpty()) {
@@ -229,7 +229,7 @@ int main(int argc, char *argv[])
auto *appWindow = qobject_cast<QQuickApplicationWindow *>(appWndComp.create());
if (!appWindow) {
- qWarning() << "Error: failed to grab application window.";
+ qWarning() << "Error: failed to create application window.";
QGuiApplication::exit(2);
}
@@ -259,9 +259,7 @@ int main(int argc, char *argv[])
}
int retVal = a.exec();
-#ifdef GRABBERDEBUG
- printf("...retVal=%i\n", retVal);
-#endif
+ qCDebug(lcGrabber) << "...retVal=" << retVal;
return retVal;
}