Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14243

Python attribute error when I clearly defined the attribute in the class constructor

$
0
0

I have a pyqt program and I'll only show a part of it as everything else works fine until I click on something that activates this bit of code:

class chTab(QDialog):    def __init__(self, chname):        super().__init__()        global tabwidget        global msgStrm        self.textBrowser = QTextBrowser()        self.chname = chname        self.layout = QVBoxLayout()        self.layout2 = QVBoxLayout()        self.layout3 = QVBoxLayout()        msgStrm = ircHandler(chname)        self.layout2.addWidget(self.textBrowser)        self.setLayout(self.layout2)        self.workerthread = WorkerThread()        self.workerthread.start()        print(self.textBrowser)    @pyqtSlot('PyQt_PyObject', str)    def addMsg(self, msgSig):        self.textBrowser.append(msgSig)class WorkerThread(QThread):    msgSig = pyqtSignal('PyQt_PyObject', str)    def run(self):        self.msgSig.connect(chTab.addMsg)        global msgStrm        for message in msgStrm.recieve():            self.msgSig.emit(chTab, str(message))

A basic explanation of the code would be that in WorkerThread I have a global variable called mgStrm which is an object containing a stream of messages, this is not a problem. The worker thread is activates by the end of chtab and it executes fine until it activates the slot specifically self.textBrowser.append(msgSig) where I get the error:AttributeError: type object 'chTab' has no attribute 'textBrowser'However I clearly do have that defined early on in the class, so I do not understand what is causing this error.

I have tried different indentations and it is definitely not an indentation error, so if someone could help me I would appreciate it since I have searched for answers.


Viewing all articles
Browse latest Browse all 14243

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>