Help understanding Qthread, Pyside
-
i am trying to understand how to do a Qthread and i have this skeletal code. my main objective is to not let the GUI "hang" while the backend is doing some database stuff and at the same time updating a table widget in the GUI. background: Doing this on Windows OS. Pyside as the GUI. (I also tried Python threading, but everytime my application crashes)
@class GenericThread(QtCore.QThread):
def init(self, function, *args, **kwargs):
QtCore.QThread.init(self)
self.function = function
self.args = args
self.kwargs = kwargsdef __del__(self): self.wait() def run(self): self.function(*self.args,**self.kwargs) return
clas myMainGUI(...)
def add(self):
...
for myfiles in os.listdir(..): <--- intensive process, lots of files
column headers = [ .... ]
result = select_data_from_file(myfiles) <----- database file processing
self.insert_table_widget ( column headers, result ) <--want to insert to widge in "realtime" and do other stuff without GUI getting "hang"
....
self.mythread.emit() <-- ??def coolie(self): # some button will call this function. if buttonclick == "add": self.mythread = GenericThread(self.add) self.mythread.disconnect() <------?? self.mythread.connect() <------ ?? self.mythread.start() @
any idea how should my emit(), connect() or disconnect() be? thanks