[Interest] How to get destructor called in object that was moved to a thread?

Murphy, Sean smurphy at walbro.com
Mon Aug 17 23:34:17 CEST 2015


I'm struggling to get my destructor called in a class of mine that is moved to a separate thread

In my class's header file:
class myClass
{
  Q_OBJECT
  ...
}

In my class's .cpp file:
myClass::~myClass()
{
  qDebug("myClass destructor");
}

MainWindow.h:
  QThread* myThread;
  myClass* mine;

My mainwindow's .cpp file:
MainWindow::MainWindow(QWidget *parent)
{
  mine = new myClass();
  myThread = new QThread(this);
  mine->moveToThread(myThread);
  myThread->start();
}

  MainWindow::~MainWindow()
{
    myThread ->exit();
    delete ui;
}

When I run my application, myClass functions properly, signals and slots in it are being called. But when the user clicks the MainWindow's 'X' button to close the application, the destructor for my class is never called, or at least that qDebug() statement is never printed to the console.

Any thoughts?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150817/92f1c78b/attachment.html>


More information about the Interest mailing list