假設在單線程應用中,我已創建了一個服務器和連接與像以下新的連接到達信號的槽,單線程應用QT時隙執行哪個線程
connect(mTcpServer, SIGNAL(newConnection()), this, SLOT(newClientConnected()));
和這條線我進入後一個巨大的循環,我做了一些計算。因此,我的單線程是主線程正在循環中忙碌,現在有新的連接到達。
所以我的問題是,
1) In which thread the new slot will be executed? I ask this because
main thread is already executing some code in a loop.
2) In which thread the event loop is maintained? Because certainly my single
thread is executing some code in a loop and is not maintaining the event loop.
我在QT :(
我不太明白這個問題:你說你有一個單線程應用程序。如在:只有一個線程。詢問插槽執行的線程是奇怪的:只有一個線程,您已經知道插槽將執行的線程! –
@ KubaOber,我想不管事件循環總是在處理中。這就是爲什麼我很好奇,如果主線程不可用於處理那麼誰是它。 – Tahlil
您需要提出一個更基本的問題:您爲什麼認爲信號和時隙與事件循環有什麼關係?在你的情況下,信號插槽連接**完全像**使用函數指針。插槽在信號的主體內被調用。當信號返回時(這只是一種方法,畢竟),插槽已被調用。沒有任何事件循環出現。事件循環用於提供跨線程/排隊插槽調用,但是你沒有這樣做。 –