gpt4 book ai didi

python - PyQt4工作线程, "QThread.started"丢失

转载 作者:行者123 更新时间:2023-12-01 05:54:59 25 4
gpt4 key购买 nike

我正在尝试在 PyQt4 应用程序中正确设置工作线程,但由于某种原因,来自线程的启动信号没有传播到我的工作线程!

    syncThread = QtCore.QThread()
self._syncThread = syncThread
worker = SyncWorker(self.async_sync)
worker.moveToThread(syncThread)
syncThread.started.connect(self.progress.show) #This dialog appears!
syncThread.started.connect(worker.work) # This seems to be a no-op
worker.finished.connect(syncThread.quit)
worker.finished.connect(worker.deleteLater)
syncThread.finished.connect(worker.deleteLater)
syncThread.finished.connect(syncThread.deleteLater)
syncThread.start()

class SyncWorker(QtCore.QObject):

# Emitted whenever done
finished = QtCore.pyqtSignal()

def __init__(self, delegate):
QtCore.QObject.__init__(self)

@QtCore.pyqtSlot()
def work(self):
print("Worker gonna work") #This never prints!
self.finished.emit()

有什么想法吗?

谢谢!

更新:按照 Gary Hughes 重命名worker -> self.worker 后,我在崩溃之前收到一个新错误

QObject::setParent: Cannot set parent, new parent is in a different thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
python: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.
Segmentation fault

更新#2没关系!我的工作人员正在调用 GUI 代码,这导致了新的错误。使用 self.worker 的原始修复是正确的。

最佳答案

尝试将 worker 重命名为 self.worker

在我看来,worker 在您调用 syncThread.start() 后立即被删除,因为它超出了范围。

关于python - PyQt4工作线程, "QThread.started"丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13042604/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com