• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 195

Backtrace:

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/views/question.php
Line: 195
Function: _error_handler

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/controllers/Questions.php
Line: 416
Function: view

File: /home/u125378470/domains/lawhelpguru.org/public_html/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

How to access signal from another widgets worker thread?

<button aria-describedby="--stacks-s-tooltip-m7lvu9qj" aria-label="Bookmark" aria-pressed="false" class="js-bookmark-btn s-btn s-btn__unset c-pointer py4 js-gps-track" data-controller="s-tooltip" data-gps-track="post.click({ item: 1, priv: 0, post_type: 1 })" data-s-tooltip-placement="right" data-selected-classes="fc-yellow-600"></button><svg aria-hidden="true" class="mln2 mr0 svg-icon iconHistory" height="18" viewbox="0 0 19 18" width="19"></svg>

 

I have a signal emitted from a worker thread to the widget 'Display' which creates that worker thread.

class worker(QObject):
    msg = pyqtSignal(str)

    @pyqtSlot()
    def __init__(self):
        super(worker, self).__init__()
        self.running = True      

    def work(self):
        while self.running:
            try:
                x =0
                rxData = "Hello World"
                while x<5:
                    x += 1
                    self.msg.emit(f"{rxData} {x}")
                    time.sleep(1)
                else:
                    self.running = False
            except:     
                self.msg.emit('An exception has occurred')
                self.running = False

        self.finished.emit()       


class Display(QWidget):
    def __init__(self,  parent=None):
        super(Display, self).__init__()
        uic.loadUi('DisplayWidget.ui', self) 
        
        self.msgBox()
        self.show()

    def start_loop(self):
        self.worker = worker()  
        self.thread = QThread() 
        self.worker.moveToThread(self.thread)  
        self.thread.started.connect(self.worker.work)         
        self.worker.msg.connect(self.msg)
        self.worker.finished.connect(self.thread.quit)  
        self.worker.finished.connect(self.worker.deleteLater)  
        self.thread.finished.connect(self.thread.deleteLater)  
        self.thread.start()

#display thread text in text box
    def msg(self, data):
        self.txBox.append("{}".format(data))        

    def msgBox(self):
        self.btn.clicked.connect(lambda: self.start_loop())
        self.btn.setEnabled(True)

I now want create a new widget that is able to use the same signal for a different purpose. How do I access the signal from the worker in NewWidget?

class NewWidget(QWidget):
    def __init__(self,  parent=None):
        super(NewWidget, self).__init__()
        
        *get the signal from worker
        *do something with it