2

I have a strange problem. Here is my code:

def method1(self, arg1, delay=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

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Developer09
  • 169
  • 2
  • 10

2 Answers2

11

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))
alexisdm
  • 29,448
  • 6
  • 64
  • 99
1

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).

TorelTwiddler
  • 5,996
  • 2
  • 32
  • 39
  • Thanks for your response. You're right. Now I get in "B" the same than in "A". BUT, I get this too: "Object::connect: Parentheses expected, slot RandomClassFromHell::". Do you know how can I get rid of it? – Developer09 Sep 20 '11 at 18:03
  • Oh, and the line is this: QtCore.QTimer.singleShot(1, self, QtCore.SLOT(recall(arg1))), because it has problems with that aditional argument XD. Sorry, it's difficult to write in this small edit box. – Developer09 Sep 20 '11 at 18:07
  • Sorry, I don't know anything about `Qt` or `SLOT`. You'll probably need to ask a new question with your updated code and question. – TorelTwiddler Sep 20 '11 at 18:23
  • Well, I've done a workaround w/o using arg1. I prefer not to risk. Anyway you've been helpful 'cause I need to know this for another thing I have to implement. Thanks! – Developer09 Sep 21 '11 at 08:14
  • Even if it does print the same thing, the `recall(arg1)` is evaluated at the time the line is executed, and not after the timer times out. – alexisdm Sep 21 '11 at 09:35