这个是网上找到信号与槽之前传参的例子,希望对大家有用。
import sys
from time import time
from PyQt4.QtCore import *
class A (QObject):
def __init__(self):
QObject.__init__(self)
from time import time
from PyQt4.QtCore import *
class A (QObject):
def __init__(self):
QObject.__init__(self)
#定义一个发射信号的方法,i为信号所带的参数
def afunc (self, i):
self.emit(SIGNAL("doSomePrinting(int)"), i)
def afunc (self, i):
self.emit(SIGNAL("doSomePrinting(int)"), i)
#这里是对应信号'doSomePrinting(int)'的槽处理函数,i为来自信号的参数
def bfunc(self, i):
print "Hello World!", i
sys.exit()
if __name__=="__main__":
app=QCoreApplication(sys.argv)
a=A()
def bfunc(self, i):
print "Hello World!", i
sys.exit()
if __name__=="__main__":
app=QCoreApplication(sys.argv)
a=A()
#将信号和槽连接
QObject.connect(a,SIGNAL("doSomePrinting(int)"),a.bfunc)
#调用信号发射函数
QObject.connect(a,SIGNAL("doSomePrinting(int)"),a.bfunc)
#调用信号发射函数
a.afunc(10)
sys.exit(app.exec_())
sys.exit(app.exec_())
本文提供了一个使用 PyQt4 实现信号与槽之间传递参数的示例,展示了如何定义信号、创建槽函数并进行连接,以及在主函数中触发信号来执行特定操作。
452

被折叠的 条评论
为什么被折叠?



