在后台线程中运行PySide会在exi上崩溃

2024-04-26 00:13:13 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码:

import threading
import time
import sys

from PySide.QtCore import *
from PySide.QtGui import *

def do_all():
    # global app, wid
    app = QApplication(sys.argv)

    wid = QWidget()
    wid.setWindowTitle('Simple')
    wid.show()

    app.exec_()
    print "exiting thread"
    time.sleep(1)

t = threading.Thread(target=do_all)
t.start()
t.join()

time.sleep(1)
print "exiting main"

这将打开一个窗口,如预期的那样。当我关闭它时,会发生三件事:

  1. 执行第一次打印
  2. 执行第二次打印

  3. enter image description here

我做错什么了?你知道吗


Tags: fromimportapp密码timesyssleepall