From ac36fa53e970bf79d68499b52433d33ed994c4c5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 3 Dec 2016 07:10:12 +0100 Subject: tracker/{aruco,pt}: use RAII for QObject --- tracker-pt/ftnoir_tracker_pt.cpp | 27 +++++++++------------------ tracker-pt/ftnoir_tracker_pt.h | 8 +++++--- 2 files changed, 14 insertions(+), 21 deletions(-) (limited to 'tracker-pt') diff --git a/tracker-pt/ftnoir_tracker_pt.cpp b/tracker-pt/ftnoir_tracker_pt.cpp index ca25e858..0e43b812 100644 --- a/tracker-pt/ftnoir_tracker_pt.cpp +++ b/tracker-pt/ftnoir_tracker_pt.cpp @@ -19,8 +19,6 @@ //----------------------------------------------------------------------------- Tracker_PT::Tracker_PT() : - video_widget(nullptr), - video_frame(nullptr), point_count(0), commands(0), ever_success(false) @@ -32,13 +30,7 @@ Tracker_PT::~Tracker_PT() { set_command(ABORT); wait(); - if (video_widget) - delete video_widget; - video_widget = NULL; - if (video_frame) - { - if (video_frame->layout()) delete video_frame->layout(); - } + // fast start/stop causes breakage camera.stop(); } @@ -180,7 +172,7 @@ void Tracker_PT::run() video_widget->update_image(frame_); } } - qDebug() << "pt: Thread stopping"; + qDebug() << "pt: thread stopped"; } void Tracker_PT::apply_settings() @@ -209,17 +201,16 @@ void Tracker_PT::apply_settings() qDebug() << "pt: done applying settings"; } -void Tracker_PT::start_tracker(QFrame *parent_window) +void Tracker_PT::start_tracker(QFrame* video_frame) { - video_frame = parent_window; video_frame->setAttribute(Qt::WA_NativeWindow); - video_frame->show(); - video_widget = new cv_video_widget(video_frame); - QHBoxLayout* video_layout = new QHBoxLayout(parent_window); - video_layout->setContentsMargins(0, 0, 0, 0); - video_layout->addWidget(video_widget); - video_frame->setLayout(video_layout); + video_widget = qptr(video_frame); + layout = qptr(video_frame); + layout->setContentsMargins(0, 0, 0, 0); + layout->addWidget(video_widget.data()); + video_frame->setLayout(layout.data()); video_widget->resize(video_frame->width(), video_frame->height()); + video_frame->show(); start(); } diff --git a/tracker-pt/ftnoir_tracker_pt.h b/tracker-pt/ftnoir_tracker_pt.h index 020694ae..66928655 100644 --- a/tracker-pt/ftnoir_tracker_pt.h +++ b/tracker-pt/ftnoir_tracker_pt.h @@ -18,12 +18,14 @@ #include "point_tracker.h" #include "compat/timer.hpp" #include "cv/video-widget.hpp" +#include "compat/util.hpp" #include #include #include #include #include +#include #include #include #include @@ -65,12 +67,12 @@ private: QMutex camera_mtx; QMutex data_mtx; - CVCamera camera; + Camera camera; PointExtractor point_extractor; PointTracker point_tracker; - cv_video_widget* video_widget; - QFrame* video_frame; + qshared video_widget; + qshared layout; settings_pt s; Timer time; -- cgit v1.2.3