1

I have a QMainWindow that is used to browse and view images with. These images are special medical images that are read using a wrapper that I wrote.

The GUI has a QListview on the left, which shows a list of thumbnails. When the user selects one of them, the QVTKWidget displays the corresponding image on the right. I use a vtkRenderWindowInteractor to manipulate the displayed image.

My main looks like the following:

#include <QApplication>
#include "GUIClassName.h" //inherits from QMainWindow
int main(int argc, char *argv[])
{
    QApplication a(argc, argv); 
    GUIClassName w;
    w.show();
    return a.exec();
}

My closeEvent looks like the following:

void GUIClassName::closeEvent(QCloseEvent* event)
{
   // mainInteractor is a vtkSmartPointer<vtkRenderWindowInteractor>    
   if (this->_mainInteractor != NULL) 
        this->_mainInteractor->TerminateApp();
    event->accept();
}

The issue is that when I close the QMainWindow, the application does not terminate. That is the command prompt stays open and Press any key to continue does not appear. If I Ctrl+break, then the application exits (obviously) but I get the following message:

QObject::~QObject: Timers cannot be stopped from another thread

I have noticed that if I only select one thumbnail and display it in the QVTKWidget, the program terminates just fine. But when I select one thumbnail, display it and then select another thumbnail, then the program does not terminate when I close the window.

I was wondering if anyone could tell me what I am doing wrong here. I would gladly copy/paste more code, but I am not sure which parts are relevant at the moment.

I have read the following in hopes of an answer, but so far I have been unable to solve this issue:

Qt app stays in memory even after MainWindow is closed

Qt process stays in memory after application closes

C++ application does not kill all processes on exit

Thanks

Community
  • 1
  • 1
siavashk
  • 436
  • 7
  • 24

2 Answers2

0

Did you stop all your threads? I'm not familiar with VTK, but looks like someone run some code in thread and did not stop them properly.

RazrFalcon
  • 787
  • 7
  • 17
  • I do not think that I explicitly start any threads, but I might be implicitly creating/starting one. I will edit my question to provide more information. – siavashk Aug 26 '15 at 18:35
0

RazrFalcon gave me a good hint. I am not an expert in Qt (yet) so I was looking for the Qthread that was being executed at all the wrong places.

The answer lies in the vtkRenderWindowInteractor class. For most vtkObjects (if I am not mistaken), calling new on the vtkSmartPointer deletes/stops the object if it already exists. However, this does not happen for vtkRenderWindowInteractor.

The solution was the following. When switching between thumbnails, I had to check for the existence of the interactor and if it was running, I would just call

    this->_mainInteractor->TerminateApp();

to stop the hidden Qthread.

siavashk
  • 436
  • 7
  • 24