• 4113阅读
  • 3回复

[提问]求事件的循环机制讲解 [复制链接]

上一主题 下一主题
离线17611904
 
只看楼主 倒序阅读 楼主  发表于: 2011-06-29
在《The book of Qt4》上看到这么一段话:
The call to exec() starts the event loop which is in charge of forwarding application events to the appropriate objects.Such events are caused by user actions, such as clicking a button.
The event loop is terminated when the quit() function of the QApplication object is called.

还有这么一句话:Finally we start the event loop and pass the return code from the event loop back as the application's return value. A simple return 0; would terminate the application immeditately without even display the window.


比如下面这个例子:
  1. #include <QApplication>
  2. #include <QLabel>
  3. int main(int argc, char *argv[])
  4. {
  5.     QApplication a(argc, argv);
  6.     QLabel label("Hello World");
  7.     label.show();
  8.     
  9.     return a.exec();
  10. }


求大家帮忙通过这个小程序解释下循环机制。

是a.exec()开始事件循环吗?那return a.exec()与结束的花括号之间是如何执行的?
return a.exec()是指a.exec()这个事件循环返回一个值,然后通过return 这个值来结束程序?

离线dbzhang800

只看该作者 1楼 发表于: 2011-06-29
引用楼主17611904于2011-06-29 08:42发表的 求事件的循环机制讲解 :
是return a.exec()开始事件循环吗?那return a.exec()与结束的花括号之间是如何执行的?
.......

1。 是。


2。 你觉得循环不结束,它会向下执行么?
离线17611904
只看该作者 2楼 发表于: 2011-06-29
回 1楼(dbzhang800) 的帖子
我想知道的是,在程序开始与a.exec()之间,以及a.exec()和程序结束之间,都是什么阶段?发生了什么?
离线dbzhang800

只看该作者 3楼 发表于: 2011-06-29
Re:回 1楼(dbzhang800) 的帖子
引用第2楼17611904于2011-06-29 10:25发表的 回 1楼(dbzhang800) 的帖子 :
我想知道的是,在程序开始与a.exec()之间,以及a.exec()和程序结束之间,都是什么阶段?发生了什么?

这个东西一两句说不清了。你真想知道的话,就在debug模式下,逐条执行呗。
快速回复
限100 字节
 
上一个 下一个