didn't work,

Even I don't understand how closing QT application will terminate main program.

As long as I understand, I using an instance of QT class, and when user closed the widget, this instance will gone, but how it can effect my other function with infinite loop. So if I can find a way which inform me that instance of Qt class is closed, I think that I can solve my problem.