十分感谢您的回复。close()与点击关闭按钮是平行的那就讲得通了。如下是我的理解不知是否正确。
//
// QtWndProc() receives all messages from the main event loop
//
该函数接收所有系统消息,当收到WM_CLOSE则调用QETWidget::translateCloseEvent(MSG)
extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
case WM_CLOSE: // close window
widget->translateCloseEvent(msg);
RETURN(0); // always handled
}
QETWidget继承于QWidget,所以d_func()->close_helper()实际上就是调用QWidgetPrivate::close_helper()
bool QETWidget::translateCloseEvent(cst MSG &)
{
return d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent);
}
该函数发出closeEvent事件
bool QWidgetPrivate::close_helper(CloseMode mode)
{
...
if (mode != CloseNoEvent) {
QCloseEvent e;
if (mode == CloseWithSpontaneousEvent)
QApplication::sendSpontaneousEvent(q, &e);
else
QApplication::sendEvent(q, &e);
if (!that.isNull() && !e.isAccepted()) {
data.is_closing = 0;
return false;
}
}
...
}
QWidget::close()同理调用QWidgetPrivate::close_helper()
bool QWidget::close()
{
return d_func()->close_helper(QWidgetPrivate::CloseWithEvent);
}