(Jul-16-2018, 12:45 PM)Alfalfa Wrote: You have to use a QThread for your freq analyzer, then emit a signal to update the gui. For PyQt4 it would be something like this:
import sys import time from PyQt4 import QtGui, QtCore class WorkerThread(QtCore.QObject): updateFreq = QtCore.pyqtSignal(int) def __init__(self): super().__init__() @QtCore.pyqtSlot() def run(self): freq = 0 while True: freq += 1 self.updateFreq.emit(freq) time.sleep(5) class Main(QtGui.QMainWindow): def __init__(self): super().__init__() self.worker = WorkerThread() self.workerThread = QtCore.QThread() # Move the Worker object to the Thread object self.workerThread.started.connect(self.worker.run) # Init worker run() at startup self.worker.moveToThread(self.workerThread) self.worker.updateFreq.connect(self.updateFreq) # Connect your signals/slots self.workerThread.start() def updateFreq(self, freq): #self.ui.freqLabel.setText(str(freq) + " Hz") print(freq) if __name__== '__main__': app = QtGui.QApplication([]) gui = Main() sys.exit(app.exec_())
Ah thank you very much!
I'll try to run a test now
EDIT:
so I've try to run it to see what it does... so got an error (of course it'll but...)
Traceback (most recent call last): File "C:/Users/user/Desktop/Python sound recog/qt_audio_monitor/TEST/QthreadFreq.py", line 35, in <module> gui = Main() File "C:/Users/user/Desktop/Python sound recog/qt_audio_monitor/TEST/QthreadFreq.py", line 21, in __init__ super().__init__() TypeError: super() takes at least 1 argument (0 given)What's this super() do anyway? sorry if I asking you a lot