Portál AbcLinuxu, 10. května 2025 01:22
self.MainWindow.statusBar().showMessage(u'Seznam aktualizován')
Když to udělám v threadu2, ukončí se program s chybou, že nemůžu přistupovat ke GUI z jiného threadu. Naopak, když dám while cyklus (jestli vlákno ještě žije) do hlavního, defaultního threadu, tak se GUI objeví, až když ten while skončí a to i přesto, že se ten cyklus nachází za self.MainWindow.show()
.
Ještě doplním, nové vlákno zakládám takhle:
self.thread2 = threading.Thread(target = self.test_internetu)
a startuji
self.thread2.start()
Poradí někdo, jak to vyřešit? Jsem v tomhle nováček. Děkuji předem
Řešení dotazu:
self.thread = MainThread(self) self.changeStartButton(0) self.connect(self.thread, QtCore.SIGNAL("output"), self.updateUi) self.connect(self.thread, QtCore.SIGNAL("failed"), self.failed) self.connect(self.thread, QtCore.SIGNAL("newValue"), self.progressBar.setValue) self.connect(self.thread, QtCore.SIGNAL("finished()"), self.changeStartButton)
class MainThread(QtCore.QThread): def __init__(self, parent): QtCore.QThread.__init__(self, parent) self.progress = IterateProgress(self,parent.progressBar) self.parent = parent def prepare(self,setting): self.setting = setting def run(self): print 'RUN' try: output_list = tomography(self.setting, self.progress) # vlastní program !!! except KeyboardInterrupt: self.emit(QtCore.SIGNAL("newValue"),0) return except: self.emit(QtCore.SIGNAL("failed")) self.emit(QtCore.SIGNAL("newValue"),0) raise return else: self.emit(QtCore.SIGNAL("output"),output_list)
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.