syxzsyxz1 2021-07-27 05:18 采纳率: 0%
浏览 1508
已结题

PyQT5 多线程 程序关闭时报错RuntimeError: wrapped C/C++ object of type QTimer has been deleted

学习PyQT5时,例子程序:Chapter07:qt07_signalSlotThreaad
程序运行没问题,但是运行以后,关闭或者stop,均报错:

RuntimeError: wrapped C/C++ object of type QTimer has been deleted

img

程序代码:

#-*- encoding: gb2312 -*-
import string, threading, time
from PyQt5.QtCore import QThread ,  pyqtSignal,  QDateTime 
from PyQt5.QtWidgets import QApplication,  QDialog,  QLineEdit
import time
import sys
def thread_main(a):
    global count, mutex
    # 获得线程名
    threadname = threading.currentThread().getName()
 
    for x in range(0, int(a)):
        # 取得锁
        mutex.acquire()
        count = count + 1
        # 释放锁
        mutex.release()
        print (threadname, x, count)
        time.sleep(1)

def showthetime():
    while True:
        data = QDateTime.currentDateTime()
        currTime = data.toString("yyyy-MM-dd hh:mm:ss")
        #self.update_date.emit( str(currTime) )
        time.sleep(1)
        print(currTime)
 
def main(num):
    
    global count, mutex
    threads = []
 
    count = 1
    # 创建一个锁
    mutex = threading.Lock()
    # 先创建线程对象
    for x in range(0, num):
        threads.append(threading.Thread(target=thread_main, args=(10,)))
    # 启动所有线程
    for t in threads:
        t.start()
 
if __name__ == '__main__':

    num = 4
    # 创建4个线程
    main(4)
    t1 = threading.Thread(target=showthetime, args=())
    t1.setDaemon(True)
    t1.start()
    sys.exit()

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 8月4日
    • 创建了问题 7月27日

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?