Re: Qthread 問題

看板Python作者 (談無慾)時間6年前 (2017/12/06 22:03), 6年前編輯推噓0(001)
留言1則, 1人參與, 6年前最新討論串2/3 (看更多)
※ 引述《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 每秒讀 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.226.130.201 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1512569013.A.BEB.html

12/06 22:07, 6年前 , 1F
QList 沒有 thread-safe, 這樣讀遲早出事
12/06 22:07, 1F
我找一下我的作法 大概是這樣 初始化的時候預先塞值 QMap<QString, QString> infoDataList; infoDataList.insert("VIN", "200"); infoDataList.insert("Temp", "25"); infoDataList.insert("FanSpeed", "200"); 然後我的QThread 就是去更新裡面的值 再用demo Timer去讀取裡面的值 沒有刪除 只是更新 ※ 編輯: MOONY135 (36.226.130.201), 12/06/2017 22:13:50
文章代碼(AID): #1Q9_Yrlh (Python)
討論串 (同標題文章)
文章代碼(AID): #1Q9_Yrlh (Python)