From b94a598484bd89c8cbb91ce506eea6cc843d7c55 Mon Sep 17 00:00:00 2001 From: am0ebe <am0ebe@gmx.de> Date: Thu, 22 Feb 2024 16:30:25 +0100 Subject: [PATCH] cam: add timer member. fix double stoprecord error (when user cancels recording) --- src/cam.cpp | 10 ++++++++-- src/cam.h | 2 ++ src/core.cpp | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/cam.cpp b/src/cam.cpp index ce49737..4f3cd4f 100644 --- a/src/cam.cpp +++ b/src/cam.cpp @@ -22,8 +22,11 @@ _id(""), _state(closed), _frames(FramePtrVector(threadsPerCam())), _payloadSize(0LL), -_pixelFormat("") +_pixelFormat(""), +_timer(new QTimer(this)) { + _timer->setSingleShot(true); + connect(_timer, SIGNAL(timeout()), this, SLOT(stopRecording())); name(); } @@ -143,7 +146,7 @@ void Cam::startRecording(seconds dur) // Convert to milliseconds auto dur_ms = duration_cast<milliseconds>(dur).count(); - QTimer::singleShot(dur_ms, this, SLOT(stopRecording())); + _timer->start(dur_ms); } void Cam::startRecording(minutes dur) @@ -151,6 +154,7 @@ void Cam::startRecording(minutes dur) // Convert to seconds auto dur_s = duration_cast<seconds>(dur); startRecording(dur_s); + } /* Does: @@ -161,6 +165,8 @@ void Cam::startRecording(minutes dur) */ void Cam::stopRecording() { + _timer->stop(); + FeaturePtr pFeature; try { diff --git a/src/cam.h b/src/cam.h index 42e162c..72cac15 100644 --- a/src/cam.h +++ b/src/cam.h @@ -19,6 +19,7 @@ using VmbCPP::FramePtrVector; using std::chrono::minutes; using std::chrono::seconds; +class QTimer; class Cam; using CamPtr = std::shared_ptr<Cam>; using CamPtrVector = std::vector<CamPtr>; @@ -65,5 +66,6 @@ private: FramePtrVector _frames; VmbInt64_t _payloadSize; std::string _pixelFormat; + QTimer* _timer; }; diff --git a/src/core.cpp b/src/core.cpp index 3164c97..40a25d7 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -25,7 +25,7 @@ Core::Core() : IPrinter(), _apiStarted( false ), _sys( VmbSystem::GetInstance() ), // create and get Vimba singleton _cameras( CamPtrVector() ), - _recDuration( 6s ) //default + _recDuration( 16s ) //default { QTimer::singleShot(0, this, SLOT(init())); //delayed init to allow connections to be established -> print/error signals! } -- GitLab