Written in the terminate exit the program crashes, sometimes a test code, directly on the code, point close program occasionally collapse, in this I ask you who help analysis to see see!
class m_work: public QObject {
Q_OBJECT
Public:
M_work (parent QObject *=nullptr) {
Xdebug & lt; <"M_work" & lt;
}
~ m_work () {
}
Q_SLOT
Void m_slot (void) {
Xdebug & lt; <"M_slot" & lt; QThread: : msleep (5000);
Xdebug & lt; <"Sleep end" & lt;
}
Private:
};
The class MainWindow: public QMainWindow
{
Q_OBJECT
Public:
MainWindow (QWidget * parent=nullptr);
~ MainWindow ();
Private slots:
Void on_btn_close_released ();
Void on_btn_open_released ();
Signals:
Void sig ();
Private:
Ui: : MainWindow * Ui;
M_work * work;
QThread * m_thread;
};
MainWindow: : MainWindow (QWidget * parent)
: QMainWindow (parent)
, the UI (new UI: : MainWindow)
{
The UI - & gt; SetupUi (this);
Xdebug & lt; <"The MainWindow" & lt;
The work=new m_work;
M_thread=new QThread (this);
The work - & gt; MoveToThread (m_thread);
M_thread - & gt; start();
The connect (this, & amp; MainWindow: : sig, work, & amp; M_work: : m_slot);
}
MainWindow: : ~ MainWindow ()
{
Xdebug & lt; <"~ MainWindow";
Delete the work;
The delete m_thread;
Delete the UI;
}
Void MainWindow: : on_btn_close_released ()
{
Xdebug & lt; <"On_btn_close_released";
M_thread - & gt; The quit ();
If (m_thread - & gt; Wait (1000)==false) {
Xdebug & lt; <"M_thread the terminate";
M_thread - & gt; The terminate ();
M_thread - & gt; wait();
}
QApp - & gt; The quit ();
}
Void MainWindow: : on_btn_open_released ()
{
Xdebug & lt; <"On_btn_open_released";
Emit sig ();
}