Message 1 of 1
Maya crash when interacting UI through QThread
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I found this simple example always crashes Maya (version 2023) if it tried to do something with my custom UI in QThread. Is there anything I should concern about when using QThread in Maya (like avoid access UI in QThread) ?
try:
from PySide2 import QtGui, QtCore, QtWidgets
except:
from PySide import QtGui, QtCore, QtWidgets
import time
class CountDownWindow(QtWidgets.QWidget):
def __init__(self):
super(CountDownWindow, self).__init__()
self.setWindowTitle('Count Down Window')
self.setGeometry(50, 50, 200, 150)
self.number_label = QtWidgets.QLabel('0', self)
class MainWindow(QtWidgets.QWidget):
def __init__(self):
super(MainWindow, self).__init__()
self.setWindowTitle('Main Window')
self.button = QtWidgets.QPushButton('Start Count Down', self)
self.button.clicked.connect(self._button_clicked_callback)
def _button_clicked_callback(self):
count_down_window = CountDownWindow()
count_down_window.show()
my_thread = MyThread(count_down_window)
my_thread.start()
class MyThread(QtCore.QThread):
def __init__(self, my_window):
super(MyThread, self).__init__()
self.my_window = my_window
def run(self):
for i in range(10):
time.sleep(1)
self.my_window.number_label.setText(str(i))
main_window = MainWindow()
main_window.show()