From 1141a15d083a30aa1ad6195050e0ea868e816eb4 Mon Sep 17 00:00:00 2001 From: Roel Standaert Date: Thu, 23 Jul 2020 13:32:57 +0200 Subject: [PATCH] Connect WTimer's timeout() signal first in constructor This is so that you can add a slot that restarts a singleshot timer. Otherwise, you have to make sure you connect the slot after calling start(). This code wouldn't work properly: timer->setSingleShot(true); timer->timeout().connect([timer]{ timer->start(); }); timer->start(); Because this would cause: start(), start(), stop() This: timer->setSingleShot(true); timer->start(); timer->timeout().connect([timer]{ timer->start(); }); would correctly cause: start(), stop(), start() --- src/Wt/WTimer.C | 9 ++------- src/Wt/WTimer.h | 3 +-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Wt/WTimer.C b/src/Wt/WTimer.C index bbea3ae6d8..609bd4ee9f 100644 --- a/src/Wt/WTimer.C +++ b/src/Wt/WTimer.C @@ -17,13 +17,13 @@ namespace Wt { WTimer::WTimer() : uTimerWidget_(new WTimerWidget(this)), - singleShot_(false), interval_(0), + singleShot_(false), active_(false), - timeoutConnected_(false), timeout_(new Time()) { timerWidget_ = uTimerWidget_.get(); + timeout().connect(this, &WTimer::gotTimeout); } EventSignal& WTimer::timeout() @@ -63,11 +63,6 @@ void WTimer::start() !timeout().isExposedSignal()); timerWidget_->timerStart(jsRepeat); - - if (!timeoutConnected_) { - timeout().connect(this, &WTimer::gotTimeout); - timeoutConnected_ = true; - } } void WTimer::stop() diff --git a/src/Wt/WTimer.h b/src/Wt/WTimer.h index 4f8cd67e1f..2cc67232db 100644 --- a/src/Wt/WTimer.h +++ b/src/Wt/WTimer.h @@ -153,10 +153,9 @@ class WT_API WTimer : public WObject observing_ptr timerWidget_; std::unique_ptr uTimerWidget_; - bool singleShot_; std::chrono::milliseconds interval_; + bool singleShot_; bool active_; - bool timeoutConnected_; std::unique_ptr