擅长:python、mysql、java
<p>如果没有多线程,我无法实现您需要的东西,这是不可能的,因为gui只能在主线程中更新。下面是一个算法,我是如何做到这一点与多线程。在</p>
<p>假设您的应用程序正在处理图像。然后是以下线程:</p>
<ol>
<li>主线程(由GUI/QApplication派生的块类.exec())</li>
<li>例如,具有1秒间隔的计时器更新变量并调用GUI线程中的插槽,后者更新用户界面中的变量。在</li>
<li><p>在你的电脑上处理图像的线程</p>
<pre><code>def process(self):
self._status = "processing image 1"
....
def _update(self):
self.status_label.setText(self._status)
def start_processing(self, image_path):
# create thread for process and run it
# create thread for updating by using QtCore.QTimer()
# connect qtimer triggered signal to and `self._update()` slot
# connect image processing thread (use connect signal to any slot, in this example I'll stop timer after processing thread finishes)
@pyqtSlot()
def _stop_timer():
self._qtimer.stop()
self._qtimer = None
_update_thread.finished.connect(_stop_timer)
</code></pre></li>
</ol>
<p>在pyqt5中,可以从一个嵌套线程(第一级)分配pyqtvariable。因此,您可以使用setter和getter使变量成为pyqtvariable,并在setter中更新gui,或者思考如何自己完成这项工作。在</p>