Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread/Signal
#3
Thank you very much Alfalfa.

I was able to use your code to finally get mine to work.
Your example was so simple and straight forward with no ambiguity. Thank you again.

For the sake of completeness, here is a working version of the problem I posted in the beginning

from PyQt5.QtWidgets import QApplication, QDialog
from PyQt5 import QtCore
from ThreadSignalUI import Ui_MainWindow

import sys
import time

class WorkThread(QtCore.QObject):
    UpdateTextBoxSignal = QtCore.pyqtSignal(int)
    
    def __init__(self):
        super().__init__()
    
    @QtCore.pyqtSlot()
    def run(self):
        runningval = 0
        
        while runningval < 10:
            runningval += 1
            self.UpdateTextBoxSignal.emit(runningval)
            time.sleep(0.5)

        
class ThreadSignal(Ui_MainWindow):

    def __init__(self, Application):
        Ui_MainWindow.__init__(self)
        self.setupUi(Application)
        
        self.worker = WorkThread()
        self.workerThread = QtCore.QThread()
        self.workerThread.started.connect(self.worker.run)
        self.worker.moveToThread(self.workerThread)
        self.worker.UpdateTextBoxSignal.connect(self.UpdateTextBoxFunction)
    
        self.StartButt.clicked.connect(self.StartThreading)
        
    def StartThreading(self, event):
        self.workerThread.start()
        
    def UpdateTextBoxFunction(self, value):
        self.TextBox.setText(str(value))

app = 0   
app = QApplication(sys.argv)
Application = QDialog()
Program = ThreadSignal(Application)
Application.show()
app.exec_()
Reply


Messages In This Thread
Thread/Signal - by LittleGrim13 - Nov-29-2018, 02:14 PM
RE: Thread/Signal - by Alfalfa - Nov-29-2018, 08:39 PM
RE: Thread/Signal - by LittleGrim13 - Nov-30-2018, 02:35 PM

Forum Jump:

User Panel Messages

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