Qthread の実行方法を理解しようとしていますが、この骨格コードがあります。私の主な目的は、バックエンドがいくつかのデータベース処理を実行し、同時に GUI でテーブル ウィジェットを更新している間に、GUI が「ハング」しないようにすることです。背景: Windows OS でこれを行っています。GUIとしてのPyside。(Python スレッド化も試しましたが、アプリケーションがクラッシュするたびに)
class GenericThread(QtCore.QThread):
def __init__(self, function, *args, **kwargs):
QtCore.QThread.__init__(self)
self.function = function
self.args = args
self.kwargs = kwargs
def __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()
どのように私のemit()、connect()、またはdisconnect()をすべきでしょうか? ありがとう