繁体   English   中英

PyQt QTimer问题 QTimer只能和QThread启动的线程一起使用

[英]PyQt QTimer problem QTimer can only be used with threads started with QThread

我的 PyQt 应用程序有一个烦人的问题,但我修复了它。 我在这里介绍它,以便其他新手可以避免犯同样的错误。

我的 PyQt 应用程序有一个源自 QGraphicsScene 的 class。 场景自身添加了大约一百个 QPixMap。

麻烦的是,当程序退出时,我收到了大约一百条以下错误消息:


QObject::startTimer: QTimer can only be used with threads started with QThread

这是我的代码:

    from PyQt5 import QtCore, QtGui
     
    class ModelHexMap(QtGui.QGraphicsScene):
     
        def __init__(self, tilePath, mapPath, parent=None):
            QtGui.QGraphicsScene.__init__(self, parent)
            self.commonInit(tilePath, mapPath)
     
        def commonInit(tilePath, mapPath):
            # make calls to self.addPixmap()
     
    class MyForm(QtGui.QMainWindow):
     
        def __init__(self, parent=None):
            QtGui.QMainWindow.__init__(self, parent)
     
            # the following causes the error
            self.ModelHexMap = ModelHexMap("game.til", "game.map")
            # this is the correct way
            self.ModelHexMap = ModelHexMap("game.til", "game.map", self)
     
    if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        myapp = MyForm()
        myapp.show()
        sys.exit(app.exec_())
how can i fix it?

我不再努力追逐退出崩溃——只需使用 pg.exit() 并完成它。

(但如果你碰巧在 pyqtgraph 中发现了一个错误,请不要犹豫在 github 上打开一个问题)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM