Re: Qthread 問題

作者: MOONY135 (談無慾)   2017-12-06 22:03:31
※ 引述《noshare (zzz...)》之銘言:
: 因為想學習使用Qthread方式來避免pyqt的畫面會凍結的問題。
: 以下是我的程式碼
: class MyWidget(QWidget):
: def __init__(self, parent = None):
: super(MyWidget, self).__init__(parent)
: ...
: def createLayout(self):
: self.button_config= QPushButton(self)
: combo_box_option = ["1","3","5","10","20"]
: self.combo = QComboBox(self)
: for t in combo_box_option:
: self.combo.addItem(t)
: ...
: def __init__(self,parent=None):
: super(MyThread,self).__init__(parent)
: def run(self):
: for i in range(x):
: self.sec_changed_signal.emit(i)
: time.sleep(1)
: 想知道有沒有辦法讓最後一個for迴圈裡面的x值,
: 能夠等於前一個class裡面最後一行下拉式選擇後的config_result
: 或是有其他種寫法可以達成在使用迴圈時,GUI不會出現無法反應的狀態。
: 謝謝各位~
我會建議你另外開一個存資料的地方 QList之類的
Qthread去裡面更新資料 另外一個地方是給GUI去
讀取裡面的資料
可能用timer 每秒讀
作者: uranusjr (←這人是超級笨蛋)   2017-12-06 22:07:00
QList 沒有 thread-safe, 這樣讀遲早出事

Links booklink

Contact Us: admin [ a t ] ucptt.com