简体   繁体   中英

PyQt5 Qthread attribut error, calling self.somelist

I have several thread. and very long main script.

I tried several solution from others but no result.

I understand attrubution error is very basic thing

in my main

@pyqtSlot()
def save_usermade(self):
    user_id = self.lineEdit_4.text().strip()
    input5 = [user_id, and some more strings...]
    self.WorkerD_1 = Worker4_1()
    self.sig_1.connect(self.WorkerD_1.save_ad)
    self.WorkerD_1.start()
    self.sig_1.emit(input5)
    self.WorkerD_1.sig4_1_1.connect(self.append_table)

in my thread

class Worker4_1(QThread):
    sig4_1_1 = pyqtSignal(str)

    def __init__(self, parent=None):
        QtCore.QThread.__init__(self, parent)

    def save_ad(self, listD_1):
        self.adlist = listD_1        

    def run(self):
        print(self.adlit)
        userID = self.adlist[0]
        and some works to do...

I got error like this

Traceback (most recent call last):
File "C:\codes\MYPROJECT\Basic\Thread_w4_1.py", line 34, in run
    print(self.adlist)
AttributeError: 'Worker4_1' object has no attribute 'adlist'

anyone know why?

would it be because I did self.sig_1.emit(input5) after self.Worferd_1.start() ?


I changed oder self.sig_1.emit(input5) first than self.Worferd_1.start() after. it seems work fine. any one know why?

class Worker4_1(QThread):
    sig4_1_1 = pyqtSignal(str)

    def __init__(self,adList, parent=None):#edited here
        QtCore.QThread.__init__(self, parent=parent)
        self.adList = adList


    def run(self):
        print(self.adlit)
        userID = self.adlist[0]
        and some works to do...

and on main:

@pyqtSlot()
def save_usermade(self):
    user_id = self.lineEdit_4.text().strip()
    input5 = [user_id, and some more strings...]
    self.WorkerD_1 = Worker4_1(adList = input5)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM