[Kde-bindings] disconnecting a block in qtruby4
Stefano Crocco
stefano.crocco at alice.it
Wed Jan 14 10:53:00 UTC 2009
Alle martedì 13 gennaio 2009, Richard Dale ha scritto:
> The new Qt::SignalBlockInvocation will be a child of the thing you
> connected it to, and so you can use thing.children obtain it and pass it to
> a disconnect call perhaps. I can't think of a syntax for doing that which
> would look tidy enough to be added to QtRuby at the moment though.
Would it be possible to add another (optional) argument to the version of
connect which takes a block? It could be used to be passed a string which will
be set as object_name ofthe Qt::SignalBlockInvocation object, which can then
be accessed using children as you suggested. Then connect could be called like
this:
obj.connect(SIGNAL(sig(int, QString)), "test_connection"){|n, s|...}
I think that Internal.signal_connect could then become something like this:
def Internal.signal_connect(src, signal, block, name = nil)
args = (signal =~ /\((.*)\)/) ? $1 : ""
signature = Qt::MetaObject.normalizedSignature("invoke(%s)" % args).to_s
obj = Qt::SignalBlockInvocation.new(src, block, signature)
obj.object_name = name if name
return Qt::Object.connect( src,
signal,
obj,
SLOT(signature) )
end
> > On a related subject, is there a reason for which there's a
> > Qt::Object.connect class method (corresponding to the static C++ method),
> > but not a corresponding Qt::Object.disconnect class method?
>
> It works for me:
>
> class Foo < Qt::Object
> slots :my_slot
> def my_slot
> puts "In my_slot"
> end
> end
>
> app = Qt::Application.new(ARGV)
> b = Qt::PushButton.new('hello')
> foo = Foo.new
>
> Qt::Object.connect(b, SIGNAL(:clicked), foo, SLOT(:my_slot))
> Qt::Object.disconnect(b, SIGNAL(:clicked), foo, SLOT(:my_slot))
> b.show
> app.exec
>
> If you comment out the disconnect the slot gets called.
Sorry, I didn't look closely enough at the documentation. I thought that the
last two parameters were optional as in the instance-level version of the
method. So I wrote something like:
Qt::Object.disconnect btn, SIGNAL('clicked()')
and I got the message
disconnect is not a class method (ArgumentError)
Of course, now I see that the disconnect class method needs all the four
parameters.
Stefano
More information about the Kde-bindings
mailing list