0

我用 PyQt GUI 编写了一个 python 程序,它使用 imaplib 检查我是否有新邮件,下面是部分代码:

def getAccountStatus(self, accountIndex):
   # some not interesting code
   mail = imaplib.IMAP4_SSL(currentHost)
   # some not interesting code
   mail.login('user', 'pass')
   mailCount = int(mail.select("INBOX", True)[1][0])
   # some not interesting code
   serverResponse, data = mail.uid('search', None, 'UNSEEN')
   # some not interesting code
   unseenUidList = data[0].split()
   # some not interesting code
   self.emailAccountsWidget.setText("<BR>".join(self.accountStatusString))
   return [mailCount, len(unseenUidList)]

问题是,在从 imap 服务器检索数据的过程中,GUI 冻结,如果我没有显式调用窗口的重绘事件,即使 TextEdit (self.emailAccountsWidget) 也不会更新其文本。有什么办法可以避免这种情况吗?

4

1 回答 1

2

这是 Qt 中预期和记录的行为。解决方案是将工作移出 GUI 线程,例如通过使用QThread子类。

如果您想了解更多信息,您应该阅读:Qt 线程基础知识

于 2012-05-12T15:48:05.927 回答