1

Referring to the solution code reported here

How to run a timer inside a QThread?

it is not mentioned if one could encounter sigsev error in case the main (gui) thread is closed (with the X button for example).

My question is how should i handle (if should i handle it in first place) the termination of the second thread in case the GUI thread is terminated?

In case the data/events are not anymore relevant once the GUI termination has been issued can i just

m_thread->terminate();

in the MainWindow destructor or in the overridden CloseEvent()??

In case the data/events are relevant instead?

Community
  • 1
  • 1
Luigi
  • 376
  • 3
  • 16
  • 1
    Unless absolutely forced to do so, avoid trying to explicitly terminate threads in user code, especially GUI user code. Try very hard indeed to not design apps that need explicit thread termination. Never, never, set any sort of 'terminate' flag and then wait in a GUI 'OnClose' event-handler, form destructor or similar, with join() or loop or any other kind of wait. – ThingyWotsit Apr 21 '17 at 16:28
  • Possible duplicate of [Exit QThread when GUI Application exits](http://stackoverflow.com/questions/41411746/exit-qthread-when-gui-application-exits) – m7913d Apr 22 '17 at 19:58
  • See also the Qt documentation of [QThread::terminate](http://doc.qt.io/qt-5/qthread.html#terminate) and [QThread](http://doc.qt.io/qt-5/qthread.html#details) itself. A clear example is provided. – m7913d Apr 22 '17 at 20:00

1 Answers1

0

My question is how should I handle (if should I handle it in first place) the termination of the second thread in case the GUI thread is terminated?

If the GUI thread is terminated we generally have the app quit the process? Let's say "GUI thread terminating" or maybe better "exiting" or "quitting" meaning already quit the GUI event loop so that no more interaction with worker threads from GUI thread. We still may have to explicitly release certain resources managed by the worker threads or otherwise we can potentially have the process stuck while quitting waiting on their release.

Alexander V
  • 8,351
  • 4
  • 38
  • 47