From this PyQt - Modify GUI from another thread I learnt that "In Qt you should never attempt to directly update the GUI from outside of the GUI thread." This is why in my PyQt5 program I have a thread (Monitor), "run" method of which emits a signal to a slot (MainWindow.save_file), which in turn shows QtWidgets.QFileDialog.getSaveFileName and accepts user's input. So my question is: how can I make this MainWindow.save_file to return the user's input to a Monitor thread.
class Communicate(QtCore.QObject):
show_save_file = QtCore.pyqtSignal()
class Monitor(QtCore.QThread):
def run(self):
self.c = Communicate()
self.c.show_save_file.connect(MainWindow.save_file)
self.c.show_save_file.emit()
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.setupUi()
# Some other PyQt stuff here....
def save_file(self):
# I need this slot to return out_file_name to another thread, Monitor
sender = self.sender()
out_file_name = QtWidgets.QFileDialog.getSaveFileName(self, '', '', 'flv')
Any help is greatly appreciated.