+ 1

how to pass a sting in signal and slot in pyqt5 new style?

from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * import sys from PyQt5.uic import loadUi import speech_recognition as sr class main(QMainWindow): def __init__(self, parent = None): super(main, self).__init__(parent) loadUi('dhruvi.ui',self) self.threadclass = thread() self.threadclass.start() self.threadclass.Tex.connect(self.InitUI) @pyqtSlot() def InitUI(self,val ): self.setText(val) def convertAudio(): r = sr.Recognizer() sound = "" with sr.Microphone() as source: sound = r.listen(source, phrase_time_limit=5) try: text = r.recognize_google(sound) return(text) except Exception as e: return(e) class thread(QThread): Tex = pyqtSignal(str) val = "" def __init__(self, parent = None): super(thread, self).__init__(parent) def run(self): while 1: val = convertAudio() self.Tex.emit(val) if __name__ == "__main__": a = QApplication(sys.argv) app = main() app.show() a.exec_() Thank you for helping.

4th Feb 2020, 5:04 AM
AKS
AKS - avatar
1 Answer
+ 1
Try doing : @pyqtSlot(str) It specifies the types of the arguments. I hope it will work!
18th Feb 2020, 4:06 PM
Théophile
Théophile - avatar