• Create Account

## Properly Closing a QT Application

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1walsh06  Members

1406
Like
0Likes
Like

Posted 06 April 2014 - 11:48 AM

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.

### #2zylski  Members

203
Like
1Likes
Like

Posted 06 April 2014 - 01:29 PM

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

### #3walsh06  Members

1406
Like
0Likes
Like

Posted 07 April 2014 - 10:34 AM

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??

### #4BitMaster  Members

8647
Like
-1Likes
Like

Posted 08 April 2014 - 07:57 AM

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

Also, you might want to connect to this signal.

Edited by BitMaster, 08 April 2014 - 07:59 AM.

### #5BitMaster  Members

8647
Like
0Likes
Like

Posted 08 April 2014 - 08:28 AM

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'.

### #6walsh06  Members

1406
Like
0Likes
Like

Posted 08 April 2014 - 08:34 AM

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.

Edited by walsh06, 08 April 2014 - 08:34 AM.

### #7zylski  Members

203
Like
-1Likes
Like

Posted 08 April 2014 - 03:04 PM

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).

### #8walsh06  Members

1406
Like
0Likes
Like

Posted 08 April 2014 - 03:50 PM

excellent thanks. WIll try it later on.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.