2010年6月28日 星期一

QThread 之 主GUI Thread 與 子 Thread 之間通訊

原文QThread 通訊


在開始玩QThread後,愈到了Qt對於QThread的限制,也就是QThread無法直接對GUI直接控制(或建立)。

找了很多文章後,一開始是用很笨的polling方法,在GUI Thread中每當Thread啟動後,就設定QTimer,每一定的時間就去check特定變數,一旦當特定變數match到我所期望的值,立即去作相對應的GUI處理,QTimer會一直定期callback回來,直到子Thread結束運作為止。然而如此很消耗資源。

QTimer::singleShot(500, this, SLOT(refresh()));
因此,後來又找了很久,才找到上面連結QThread通訊,雖然利用connect方式,我之前就有嘗試過,很不幸的,當時沒有使用QObject::connect,使得當時compile就錯了(Qt真的很不熟~)。Login是rQThread class
QObject::connect( this->Login, SIGNAL(send(QString)), this, SLOT(receive(QString)) );
現在Thread可以通訊後,接下來腦中有關Thread延伸的想法就開始發散了..... 待續

1 則留言:

匿名 提到...

Animated Drug Pictures http://www.iowafloodstories.com/ - order phentermine Eating less and eating less often will translate into the intake of fewer calories, which will result in weight loss. [url=http://www.iowafloodstories.com/]buy phentermine no prescription[/url]

搜尋此網誌