Pyqt5 qthread + signal not working + gui freeze

前端 未结 3 1210
半阙折子戏
半阙折子戏 2020-11-30 00:35

I am trying to make a mailbox checker with imap lib, it work pretty fine with python, queue and multithread without gui.

But when I try to put a gui, ev

3条回答
  •  情话喂你
    2020-11-30 01:21

    I can't test because setimap is not available on my system. I renamed CheckerThread to Checker since it is no longer a thread (it just "lives" in a thread):

    class Checker(QtCore.QObject):
    

    Then just replace the contents of the loop in gogogo(self) with this:

    for lignesmailtocheck in sorted(setmailtocheck):
        checker = Checker(lignesmailtocheck)
    
        thread = QThread()
        checker.moveToThread(thread)
        # connections after move so cross-thread:
        thread.started.connect(checker.run)
        checker.signal.connect(self.checkedok)
        thread.start()
    
        self.threads.append(thread)
    

    It is almost always a good idea to decorate slots with pyqtSlot so both run and checkedok should be thus decorated.

    The SO answer about Qt threads is quite handy to remind yourself of details (note however that it uses old-style connections -- you have to translate C++ connect( sender, SIGNAL(sig), receiver, SLOT(slot)); to PyQt5 sender.sig.connect(receiver.slot)).

提交回复
热议问题