how to pass a sting in signal and slot in pyqt5 new style? | Sololearn: Learn to code for FREE!


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() a.exec_() Thank you for helping.

2/4/2020 5:04:20 AM


1 Answer

New Answer


Try doing : @pyqtSlot(str) It specifies the types of the arguments. I hope it will work!