multithreading - Python: thread in PyQt, emit method to get the data -
i try value of count_total_value
in user interface when call continusread
method, (it should "toto"
according want do) default value "azerty"
displayed. please can tell me wrong?
this code:
#!/usr/bin/env python3 pyqt4 import qtcore, qtgui import sys import os import subprocess import time import threading ctypes import * import ctypes #import converted python ui file test_error_rx import ui_mainwindow class mythread(qtcore.qthread): count_total_valuechanged = qtcore.pyqtsignal(str) def __init__(self, parent=none): super(mythread, self).__init__(parent=parent) self.count_total_value = 'azerty' def run(self): ##do things calculate count_total_value count_total_value='toto' self.count_total_valuechanged.emit((self.count_total_value)) time.sleep(0.1) class main( qtgui.qmainwindow,qtgui.qwidget): def __init__(self): qtgui.qmainwindow.__init__(self) self.ui = ui_mainwindow() self.ui.setupui(self) # connect buttons qtcore.qobject.connect(self.ui.continusread,qtcore.signal("clicked()"),self.continusread) self.__thread = mythread(self) self.__thread.count_total_valuechanged.connect(self.ui.count_total.settext) def continusread(self): self.__thread.start() def main(): app = qtgui.qapplication(sys.argv) window = main() window.show() sys.exit(app.exec_()) if __name__ == "__main__": main()
in run()
method of thread class mythread
set count_total_value='toto'
when should self.count_total_value='toto'
.
note when posting on stackoverflow should:
- post minimilistic working example (you haven't included ui in above code no-one can run script)
- check posted code has correct indentation , fix mistakes (your posted code mess of incorrect indentation)
Comments
Post a Comment