我想获取线程(worker)上的信号发出的值,该信号包含两个参数(两个list,或者list和int)。但是当我试图在主窗口中获取这两个列表的值时,我只得到一个列表。那么,如何从一个信号中获取主窗口中的两个列表呢
class Worker(QThread):
authResult = QtCore.pyqtSignal((list,list))
def __init__(self):
super(Worker, self).__init__()
self.flag = True
self.s="vide"
def run(self):
self.auth()
def auth(self):
c=0
Malist=[]
k=c+600
while c<10:
c+=1
time.sleep(0.3)
print(c)
Malist.append(k)
k=k+1
Malist2=['a','b','c']
self.authResult.emit( Malist,Malist2)
这是主窗口包含的按钮,我只想打印两个列表Malist和Malist2的值
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(QSize(300, 200))
self.setWindowTitle("PyQt button example ")
pybutton = QPushButton('Click me', self)
pybutton.clicked.connect(self.clickMethod)
pybutton.resize(100,32)
pybutton.move(50, 50)
pybutton2 = QPushButton('Afficher !!', self)
pybutton2.clicked.connect(self.afficher)
pybutton2.resize(60,32)
pybutton2.move(160, 50)
def clickMethod(self):
self.thread=Worker()
self.thread.authResult.connect(self.handl)
self.thread.start()
print(self.thread.s)
def handl(self,result):
print(type(result))
print(result)
print("Cc!!")
结果是: [60060160260360460606607607608609] 仅显示列表1。 需要帮忙吗
您可能会认为使用括号将允许您获得具有单个参数签名的信号,但实际情况并非如此。信号可以用multiple overloads声明(如在“不同的参数签名”中),每个信号都包含在一个序列中,如列表或元组
因此,您所做的与以下内容完全相同:
其结果与以下内容相同:
因为只有一个签名
然后,您只会收到第一个列表,因为函数只接受一个参数。如果添加第二个参数,也会收到第二个列表:
稍微不同的解决方案可能是使用单个
object
参数:有了它,
handl
函数将使用以前的基于单参数的版本相关问题 更多 >
编程相关推荐