当前位置: 代码迷 >> QT开发 >> a.exec()的功用
  详细解决方案

a.exec()的功用

热度:65   发布时间:2016-04-25 04:30:27.0
a.exec()的作用
请教各位大神,在qt程序的main函数中
C/C++ code
 int main(int argc, char *argv[]){    QApplication a(argc, argv);    MainWindow w;    w.show();    return a.exec();}


其中,return的a.exec()与直接return 0的区别是什么?
直接return 0,其w中的创建的资源有没有被回收?

------解决方案--------------------
a.exec() 进入事件循环
------解决方案--------------------
return a.exec(); 相当于把程序运行交给Qt处理,进入程序的循环状态。 return 0; 程序就直接退出了,不能达到显示的效果
------解决方案--------------------
Assembly code
Enters the main event loop and waits until exit() is called. Returns the value that was set to exit() (which is 0 if exit() is called via quit()).It is necessary to call this function to start event handling. The main event loop receives events from the window system and dispatches these to the application widgets.To make your application perform idle processing (i.e. executing a special function whenever there are no pending events), use a QTimer with 0 timeout. More advanced idle processing schemes can be achieved using processEvents().We recommend that you connect clean-up code to the aboutToQuit() signal, instead of putting it in your application's main() function because on some platforms the QCoreApplication::exec() call may not return. For example, on Windows when the user logs off, the system terminates the process after Qt closes all top-level windows. Hence, there is no guarantee that the application will have time to exit its event loop and execute code at the end of the main() function after the QCoreApplication::exec() call.
------解决方案--------------------
探讨

Assembly code
Enters the main event loop and waits until exit() is called. Returns the value that was set to exit() (which is 0 if exit() is called via quit()).

It is necessary to call this functio……

------解决方案--------------------
也可窗体独占显示
  相关解决方案