作者MOONY135 (谈无慾)
看板Python
标题Re: Qthread 问题
时间Wed Dec 6 22:03:31 2017
※ 引述《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://webptt.com/cn.aspx?n=bbs/Python/M.1512569013.A.BEB.html
1F:→ uranusjr: QList 没有 thread-safe, 这样读迟早出事 12/06 22:07
我找一下我的作法
大概是这样 初始化的时候预先塞值
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