1. <legend id='kP1k4'><style id='kP1k4'><dir id='kP1k4'><q id='kP1k4'></q></dir></style></legend>
    <i id='kP1k4'><tr id='kP1k4'><dt id='kP1k4'><q id='kP1k4'><span id='kP1k4'><b id='kP1k4'><form id='kP1k4'><ins id='kP1k4'></ins><ul id='kP1k4'></ul><sub id='kP1k4'></sub></form><legend id='kP1k4'></legend><bdo id='kP1k4'><pre id='kP1k4'><center id='kP1k4'></center></pre></bdo></b><th id='kP1k4'></th></span></q></dt></tr></i><div id='kP1k4'><tfoot id='kP1k4'></tfoot><dl id='kP1k4'><fieldset id='kP1k4'></fieldset></dl></div>
    • <bdo id='kP1k4'></bdo><ul id='kP1k4'></ul>
    1. <tfoot id='kP1k4'></tfoot>

      <small id='kP1k4'></small><noframes id='kP1k4'>

      PyQt5 - 如何从工作线程发出信号以通过 GUI 线程调

      时间:2023-08-04
    2. <legend id='Smgqw'><style id='Smgqw'><dir id='Smgqw'><q id='Smgqw'></q></dir></style></legend>

            1. <tfoot id='Smgqw'></tfoot>

                <tbody id='Smgqw'></tbody>
                <bdo id='Smgqw'></bdo><ul id='Smgqw'></ul>

                <small id='Smgqw'></small><noframes id='Smgqw'>

                <i id='Smgqw'><tr id='Smgqw'><dt id='Smgqw'><q id='Smgqw'><span id='Smgqw'><b id='Smgqw'><form id='Smgqw'><ins id='Smgqw'></ins><ul id='Smgqw'></ul><sub id='Smgqw'></sub></form><legend id='Smgqw'></legend><bdo id='Smgqw'><pre id='Smgqw'><center id='Smgqw'></center></pre></bdo></b><th id='Smgqw'></th></span></q></dt></tr></i><div id='Smgqw'><tfoot id='Smgqw'></tfoot><dl id='Smgqw'><fieldset id='Smgqw'></fieldset></dl></div>
                本文介绍了PyQt5 - 如何从工作线程发出信号以通过 GUI 线程调用事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                正如我在标题中提到的.我该怎么做?

                As I Mentioned in Title. How can i do something like this?

                class Main(QWidget):
                
                        def __init__(self):
                
                                super().__init__()
                
                        def StartButtonEvent(self):
                
                                self.test = ExecuteThread()
                                self.test.start()
                
                        def MyEvent(self):
                
                                #MainThreadGUI
                
                class ExecuteThread(QThread):
                
                        def run(self):
                
                                # A lot of work
                
                                # Signal to main thread about finishing of job = mainthread will perform MyEvent
                

                我在这里找到了一些教程 pyqt4 在线程到主线程中的插槽

                I found some tutorials here pyqt4 emiting signals in threads to slots in main thread

                这里 从 pyQt Qthread 发出信号

                但它似乎在 PyQt5 中不起作用:/

                But it seems it does not working in PyQt5 :/

                推荐答案

                只需使用 QThread.finished 信号在这里.如果您完成线程,它将自动执行.当然你也可以根据需要定义自己的自定义信号.

                Just use the QThread.finished signal here. It will be executed automatically if you finish your thread. Of course you can also define your own custom signal if you want.

                from PyQt5.QtCore import pyqtSignal
                
                class Main(QWidget):
                
                    def __init__(self):
                        super().__init__()
                
                    def StartButtonEvent(self):
                        self.test = ExecuteThread()
                        self.test.start()
                        self.test.finished.connect(thread_finished)
                        self.test.my_signal.connect(my_event)
                
                    def thread_finished(self):
                        # gets executed if thread finished
                        pass
                
                    def my_event(self):
                        # gets executed on my_signal 
                        pass
                
                
                class ExecuteThread(QThread):
                    my_signal = pyqtSignal()
                
                    def run(self):
                        # do something here
                        self.my_signal.emit()
                        pass
                

                这篇关于PyQt5 - 如何从工作线程发出信号以通过 GUI 线程调用事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:pyQt5 更改 MainWindow 标志 下一篇:Qt Designer如何改变背景

                相关文章

                最新文章

                1. <legend id='k5DbA'><style id='k5DbA'><dir id='k5DbA'><q id='k5DbA'></q></dir></style></legend>
                  <i id='k5DbA'><tr id='k5DbA'><dt id='k5DbA'><q id='k5DbA'><span id='k5DbA'><b id='k5DbA'><form id='k5DbA'><ins id='k5DbA'></ins><ul id='k5DbA'></ul><sub id='k5DbA'></sub></form><legend id='k5DbA'></legend><bdo id='k5DbA'><pre id='k5DbA'><center id='k5DbA'></center></pre></bdo></b><th id='k5DbA'></th></span></q></dt></tr></i><div id='k5DbA'><tfoot id='k5DbA'></tfoot><dl id='k5DbA'><fieldset id='k5DbA'></fieldset></dl></div>
                  • <bdo id='k5DbA'></bdo><ul id='k5DbA'></ul>

                  <small id='k5DbA'></small><noframes id='k5DbA'>

                2. <tfoot id='k5DbA'></tfoot>