Qt window to exit the loop exits of issues and events

I opened the main program in a Qt thread, thread using a signal - generating grooves QMainWindow (GUI), main function code is as follows:
int main (int argc, char * the argv [])
{
the QApplication A (argc, the argv);

NetWorkThread thread;
thread.start();

// enter event loop
return a.exec ();
}

For QMainWindow generated, after all I manually turned off, you need to send a signal to create, you can not create out ~
add breakpoints Taken together, this time signal - slots seem disconnected, then checked a lot of debugging signal slot content, but nothing to harvest.
Finally, find information, is the event loop to exit the application!
Event loop is actually similar to an event queue of events (or signal) included in the processing order of finish and time when the event is not the end of the cycle, which is actually more similar to an occupation for CPU events ( ;;)cycle. Nature is actually a way to re-queue allocation of time slices, with it, a signal occurs, the event generated to normal.
Because the main function is not the main GUI window (similar to a service program), the current program is through a GUI window signal - dynamically generated slots, QMainWindow produced acts as the main window!
But Qt for window closing event of default the following actions:
window properties: Qt :: WA_QuitOnClose
explained:. Makes the Application at The Qt quit the when the widget at The Last at The attribute with the SET has accepted closeEvent () This behavior CAN BE Modified with at The QApplication :: quitOnLastWindowClosed Property. By default the this attribute for the SET IS All Widgets of the type of Qt :: Window.
The default setting for the main window Qt :: WA_QuitOnClose, i.e. when the main window is closed, also exit the main event loop, when the signal occurs, the event is generated in response to a get ~
modification method:
1, remove the window :: the Qt WA_QuitOnClose properties
2, or by :: QGuiApplication setQuitOnLastWindowClosed set (false)

More convenient modified as follows:
int main (int argc, char * the argv [])
{
the QApplication A (argc, the argv);

NetWorkThread thread;
thread.start();

// make sure the event loop does not exit after the last window is closed
a.setQuitOnLastWindowClosed (false);

// enter event loop
return a.exec ();
}

In this case, the main event loop will not quit, similar to the service process as a resident of existence -
if you want to quit, you can send quit () signals to force the exit.

Guess you like

Origin www.cnblogs.com/MakeView660/p/11775380.html