fixed thread deletion

This commit is contained in:
canpadawan
2016-06-08 11:35:00 +02:00
parent 9ae3d4f979
commit 39e07dc3a7
2 changed files with 6 additions and 3 deletions
+5 -1
View File
@@ -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;
}
+1 -2
View File
@@ -1,10 +1,9 @@
#ifndef CANCONNECTIONCONTAINER_H
#define CANCONNECTIONCONTAINER_H
#include "canconnection.h"
#include <Qt>
#include <QThread>
#include "mainwindow.h"
#include "canconnection.h"
class CANConnectionContainer : public QObject
{