From 39e07dc3a7d0e53f9055aba96f2ecd0f431810d8 Mon Sep 17 00:00:00 2001 From: canpadawan Date: Wed, 8 Jun 2016 11:35:00 +0200 Subject: [PATCH] fixed thread deletion --- canconnectioncontainer.cpp | 6 +++++- canconnectioncontainer.h | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/canconnectioncontainer.cpp b/canconnectioncontainer.cpp index 63a5069..302a3be 100644 --- a/canconnectioncontainer.cpp +++ b/canconnectioncontainer.cpp @@ -1,5 +1,6 @@ #include "canconnection.h" #include "canconnectioncontainer.h" +#include "mainwindow.h" CANConnectionContainer::CANConnectionContainer(CANConnection *conn) { @@ -7,7 +8,6 @@ CANConnectionContainer::CANConnectionContainer(CANConnection *conn) connection = conn; connection->moveToThread(thread); - connect(thread, &QThread::finished, conn, &QObject::deleteLater); connect(thread, &QThread::started, conn, &CANConnection::run); //setup timers within the proper thread connect(conn, &CANConnection::frameUpdateRapid, MainWindow::getReference(), &MainWindow::gotFrames, Qt::QueuedConnection); connect(MainWindow::getReference(), &MainWindow::sendCANFrame, conn, &CANConnection::sendFrame, Qt::QueuedConnection); @@ -18,6 +18,10 @@ CANConnectionContainer::CANConnectionContainer(CANConnection *conn) CANConnectionContainer::~CANConnectionContainer() { //have to stop the actual execution first before deleting + thread->quit(); + if(!thread->wait()) { + qDebug() << "can't stop thread"; + } delete thread; delete connection; } diff --git a/canconnectioncontainer.h b/canconnectioncontainer.h index 9ff2b22..8a4a429 100644 --- a/canconnectioncontainer.h +++ b/canconnectioncontainer.h @@ -1,10 +1,9 @@ #ifndef CANCONNECTIONCONTAINER_H #define CANCONNECTIONCONTAINER_H -#include "canconnection.h" #include #include -#include "mainwindow.h" +#include "canconnection.h" class CANConnectionContainer : public QObject {