I was looking everywhere but I was unable to figure out answer to my problem. I need your help regarding QThread threading in PyQt5. For the purpose of learning I've created two classes in my main.py file. One of those classes is a GUI class and the other one is a thread created using QThread object.
from PyQt5 import QtCore, QtGui, QtWidgets
import threading_gui # contains GUI generated by pyuic5
class Change_values(QtCore.QThread):
def __init__(self, parent = None, str_variable, int_variable):
self.var1 = str_variable
self.var2 = int_variable
def run(self):
self.var1 += ' testing thread communication'
self.var2 += 4
class MainWindow(QtWidgets.QMainWindow, threading_gui.UI_MainWindow):
change_signal = QtCore.pyqtSignal(str, int, name='change_signal')
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.btn_Run.clicked.connect(self.process_data)
self.thread1 = Change_values('I am', 3)
def process_data(self):
self.thread1.start()
This is as far as I managed to do. Now I need someone to explain me how can I emit signal from thread Change_values and display the content of variables var1 and var2 in my GUI thread.
I was able to find examples for PyQt4 but nothing useful when it comes to PyQt5. Thank you all in advance.