Properly Closing a QT Application

Started by
6 comments, last by walsh06 10 years ago

So Im making a QT application and Im trying to figure out how to properly shut it down when the x is clicked. I have a loop running and if the x is clicked the GUI will disappear while but the program keeps running until the loop ends. Calling delete on the object with the loop just stops the loop but doesnt stop the application.

So what is the best with of dealing with shut down. I assume its going to be using the closeEvent slot in some form.

Advertisement

you need to close all threads created, not sure on the specifics of the program but whats happening is the gui is running on a different thread then the loop is if you detect that the x button is clicked have your loop thread close

I was figuring it would be something along those lines. Thanks for pointing me in the right direction anyway. Anyone have more specifics for QT??

Yes. The framework is called 'Qt' (note the lower case T).

Also, you might want to connect to this signal.
While I freely admit the initial version of my reply was not as useful as it could have been I'd also like to point out that downvoting it was unfriendly and unnecessary.

You are persistently calling a common library by the wrong name. Putting 'QT' instead of 'Qt' into a CV is quite likely to cause unnecessary problems for you (just like people writing 'JAVA' when they mean 'Java'). If there are a lot of potential candidates it might just be a reason to sort you into 'does not really know what he is talking about' instead of 'candidate'.

If you wanted to say what you did the second time then say that. Making some comment to point out a simple mistake with no context and no relevance to the question at hand is bad for everyone. Thats why I downvoted. Unfriendly yes, unnecessary.... I would say not as I assume thats the point of the voting. And I understand your reasoning and its something I will take on board. But if you have a point then say it.

So anyway, does anyone have an answer for closing the main thread of the application.


Reading a short statement I found that using
QApplication::instance()->thread()
is how to obtain the main thread. From there you should be able to end / kill / purge the thread (the function may be called join, I am not sure).

excellent thanks. WIll try it later on.

This topic is closed to new replies.

Advertisement