标签:
杂谈 |
QWidget *window = new QWidget;
可是程序运行后为什么任务管理器的进程里还有呢???请赐教~如何修改~~~
在windows+Eclipse+CDT+QT下。。。
完整代码:
#include <QApplication>
#include <QWidget>
int main(int argc, char *argv[])
{
}
-------------------------------------------------------
下面是关于 close() 函数的文档
Closes this widget. Returns true if the widget was closed; otherwise returns false.
First it sends the widget a QCloseEvent. The widget is hidden if it accepts the close event. If it ignores the event, nothing happens. The default implementation of QWidget::closeEvent() accepts the close event.
If the widget has the Qt::WA_DeleteOnClose flag, the widget is also deleted. A close events is delivered to the widget no matter if the widget is visible or not.
The QApplication::lastWindowClosed() signal is emitted when the last visible primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose attribute set is closed. By default this attribute is set for all widgets except transient windows such as splash screens, tool windows, and popup menus.
请注意红色部分,当最后一个窗口关闭的时候会产生 QApplication::lastWindowClosed() 信号,而正是这个信号使程序退出。
所以楼主认为程序应该退出,但是在调用 windows.close() 的时候,程序并没有进入消息循环,而操作系统是消息响应的,
QApplication::lastWindowClosed() 信号所对应的槽应该不会被执行。
而等程序进入app.exec() 之后,永远没有 quit() 执行,相当于进入的死循环。
不知道楼主为什么要在那个地方调用 close() 方法,在进入app.exec() 之前,创建的 Widget 可以不用关闭,程序运行结束的时候会自动关闭
复制代码
- #include <QApplication>
- #include <QWidget>
- int main(int argc, char *argv[])
- {
-
QApplication app(argc, argv); -
QWidget *window = new QWidget; -
window->showNormal(); -
return app.exec(); - }
---------------------------------------------
下面是关于 close() 函数的文档
Closes this widget. Returns true if the widget was closed; otherwise returns false.
First it sends the widget a QCloseEvent. The widget is hidden if it accepts the close event. If it ignores the event, nothing happens. The default implementation of QWidget::closeEvent() accepts the close event.
.......
调用close()是想让窗口自动关闭并退出,而不需要手动关闭窗口。
我也发现了,手动的话进程是退出的。这部分文档也看了。。。