Python Forum
PyQt Threading & Class handling
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyQt Threading & Class handling
#5
(Mar-04-2019, 11:28 AM)Alfalfa Wrote:
(Mar-04-2019, 05:50 AM)mrdominikku Wrote: @Alfalfa, thanks for response, 1st and 3rd applied, but still can't make 2nd work. It doesn't crash program or anything, but either emit signal or call class procedure don't update progress bar :( I added part of convert module below.

Your usage of threading, slot and signals is incorrect. Look again at the example I gave you above. If you have trouble understanding how it work, I propose you start with this very short threading example and grow your program around it.

Been searching for few solutions and still don't get it. In PyQt5 documentation is described how to use signals and slot, but even after using them I can't call emit signal from another module, but I can emit from same module.

#*******ui_main.py module*******

class Window(QtBaseClass, Ui_MainWindow):

    def __init__(self, parent=None):

        super(QtBaseClass, self).__init__(parent)

        self.setupUi(self)
        self.worker = ThreadClass(self) #<-- thread class initialize
        self.worker.signal.connect(self.update_progress_bar)  # <--connecting slot to signal
        
    def update_progress_bar(self, progress_val):
        self.input_progress_bar.setValue(progress_val)

    def process_input(self):
        self.worker.start()  #<-- starting thread

class ThreadClass(QThread):

    signal = QtCore.pyqtSignal(int) #<-- my signal

    def __init__(self, window, parent=None):
        super(ThreadClass, self).__init__(parent)
        self.window = window

    def run(self):
        self.signal.emit(20)  #<--that's work
        convert.convert_main(self.signal, self.window.input_line.text()) #<--pass signal to another module

#**********convert.py module****

def convert_main(s_thread, input_array):
    s_thread.emit(20) #<-- that's not working
Reply


Messages In This Thread
PyQt Threading & Class handling - by mrdominikku - Mar-02-2019, 06:02 PM
RE: PyQt Threading & Class handling - by Alfalfa - Mar-03-2019, 04:14 PM
RE: PyQt Threading & Class handling - by Alfalfa - Mar-04-2019, 11:28 AM
RE: PyQt Threading & Class handling - by mrdominikku - Mar-10-2019, 01:50 PM
RE: PyQt Threading & Class handling - by Alfalfa - Mar-10-2019, 03:12 PM
RE: PyQt Threading & Class handling - by Alfalfa - Mar-10-2019, 06:35 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020