Singleshot: SLOT with arguments
I have a strange problem. Here is my code:
def method1(self, arg1, delay=开发者_C百科True):
"""This is a method class"""
def recall(arg1):
self.method1(arg1, delay=False)
return
if delay:
print "A: ", arg1, type(arg1)
QtCore.QTimer.singleShot(1, self, QtCore.SLOT(recall(int)), arg1)
return
print "B: ", arg1, type(arg1)
So I get this in console:
A: 0 <type 'int'>
B: <type 'int'> <type 'type'>
In "B" you should get the same than in "A". Anyone knows what's wrong? How can I get the arg1 value instead of its type? This is not making any sense...
PS: I'm trying something like this: http://lists.trolltech.com/qt-interest/2004-08/thread00659-0.html
The parameter passed to the SLOT
function must be a string with types as parameters, not a direct call, so you can't connect a slot with parameters to a signal without any parameter.
You can use a lambda function instead:
QtCore.QTimer.singleShot(1, lambda : self.recall(arg1))
It looks like when you are calling this:
QtCore.QTimer.singleShot(1, self, QtCore.SLOT(recall(int)), arg1)
are you meaning to call this instead?
QtCore.QTimer.singleShot(1, self, QtCore.SLOT(recall(arg1)), arg1)
you are passing int
as the first argument of recall
, which passes it directly to method1
. int
is a type object (the type of integers).
精彩评论