以上代码在运行时会报错:QThread :Destroyed while thread is still running
原因是在MyWidget中,t是一个局部变量,当mousePressEvent函数结束后,它的生命周期也都结束了,但是这个线程里的程序很有可能还没有运行完,所以才会报错,解决方案如下
t=CustomThread(self.onMsg)
改为
self.t=CustomThread(self.onMsg)
以上代码在运行时会报错:QThread :Destroyed while thread is still running
原因是在MyWidget中,t是一个局部变量,当mousePressEvent函数结束后,它的生命周期也都结束了,但是这个线程里的程序很有可能还没有运行完,所以才会报错,解决方案如下
t=CustomThread(self.onMsg)
改为
self.t=CustomThread(self.onMsg)