Domanda

I have written a python program with a PyQt GUI that, using the imaplib, checks if I have new mails, here is part of the code:

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)]

The problem is that during this process of retrieving the data from the imap server the GUI freezes, even the TextEdit (self.emailAccountsWidget) is not updating its text if I do not explicitly call the repaint event of the window. Any workarounds to avoid this?

È stato utile?

Soluzione

That's expected and documented behaviour in Qt. The solution is to do move the work out of the GUI thread, for example by using a QThread subclass.

If you want know more, you should read: Qt Threading Basics

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top