On Monday 17 August 2015, Murphy, Sean wrote:
> 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?

Where do you delete mine? I see no delete nor any ownership. Note that unless 
you move it back you need to delete it from the body of the new thread. If the 
new thread has a runloop you can also async call the slot mine->deleteLayer().

`Alla
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to