問題描述
關于 QApplication 的 exec
函數,我了解以下內容:
I have understood the following regarding QApplication's exec
function:
QApplication exec 啟動主事件循環.它啟動 GUI.它處理信號并在接收到它們時調用適當的時隙.它一直等到 exit 被調用并返回在 exit 中設置的值.
QApplication exec starts the main event loop. It launches the GUI. It processes the signals and calls appropriate slots on receiving them. It waits until exit is called and returns the value which was set in exit.
現在,當我們說事件循環時,是否意味著在Qt內部代碼中運行了一些while循環,并且在那個while循環中寫了處理信號和槽的方法?
Now, when we say event loop, does it mean that there is some while loop running in the internal code of Qt, and in that while loop the method of handling signals and slots is written?
推薦答案
現在,當我們說事件循環時,是否意味著有一些while在 Qt 的內部代碼中運行的循環,在那個 while 循環中信號槽的處理方法有寫嗎?
Now, when we say event loop, does it mean that there is some while loop running in the internal code of Qt, and in that while loop the method of handling signals and slots is written?
從某種意義上說,是的.如今,大多數軟件都坐著等待事件——用戶輸入、網絡流量、計時器事件、傳感器等——并做出相應的響應.
In a sense, yes. Most software these days sits and waits for events -- user input, network traffic, timer events, sensors, etc. -- and responds accordingly.
這不是 Qt 特有的.這是一種常見的設計模式,從 Windows 到 Android 再到 Arduino,隨處可見.
This is not specific to Qt. It's a common design pattern you'll find everywhere from Windows to Android to Arduino.
這篇關于Qt 中的事件循環是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!