Funktionen innerhalb einer Klasse
Verfasst: Freitag 26. Februar 2021, 12:03
Servus,
ich bin noch sehr neu in der Python Welt. Und heute ist mir ein unerklärlicher Fehler (für mich zumindest
) aufgefallen. Wie kann es sein wenn ich bei wInit.signals.process.connect(dreck) dreck aufrufe es funktioniert und wenn ich self.dreckB aufrufe es nicht mehr funktioniert? Es ist nicht der ganze Code nur ein Teil. Ich benutzte Python 3.7 auf Windows.
ich bin noch sehr neu in der Python Welt. Und heute ist mir ein unerklärlicher Fehler (für mich zumindest

Code: Alles auswählen
class Worker(QRunnable):
'''
Worker thread
Inherits from QRunnable to handler worker thread setup, signals and wrap-up.
:param callback: The function callback to run on this worker thread. Supplied args and
kwargs will be passed through to the runner.
:type callback: function
:param args: Arguments to pass to the callback function
:param kwargs: Keywords to pass to the callback function
'''
def __init__(self, fn, *args, **kwargs):
super(Worker, self).__init__()
# Store constructor arguments (re-used for processing)
self.fn = fn
self.args = args
self.kwargs = kwargs
self.signals = WorkerSignals()
# Add the callback to our kwargs
self.kwargs['progress_callback'] = self.signals.progress
@pyqtSlot()
def run(self):
'''
Initialise the runner function with passed args, kwargs.
'''
# Retrieve args/kwargs here; and fire processing using them
try:
print("try")
result = self.fn(*self.args, **self.kwargs)
except:
print("except")
traceback.print_exc()
exctype, value = sys.exc_info()[:2]
self.signals.error.emit((exctype, value, traceback.format_exc()))
else:
print("else")
self.signals.result.emit(result) # Return the result of the processing
finally:
print("finally")
self.signals.finished.emit() # Done
def dreck():
print("AAAA")
class MainWindow(QMainWindow):
wInit = Worker(self.KM.InitConnection)
wInit.signals.progress.connect(dreck)
def dreckB(self):
print("BBBB")