[Kde-bindings] Qt::Object.connect for ruby-blocks

kelko kelko at anakrino.de
Sat Sep 2 16:05:13 UTC 2006


Hi,
In #kde-ruby there started a discussion of being able to pass a block
directly to Qt::Object.connect so it is called everytime a signal is
emitted. working on it and talking about it witch Richard i wrote code
to add support for such calls to qtruby.
Actually it has to be called another method to support block yet, but
we want to get it working directly in the same method.

When the file appended is required in a ruby-app you can do things like:
Qt::Object.connect2Block(Qt::PushButton.new(), SIGNAL("clicked()")) do
	puts "Hello World"
end

In the block you can access other objects available in the context
where the block was created.

You can even work with signals having arguments:

Qt::Object.connect2Block(KDE::HTMLPart.new().browserExtension,
SIGNAL("openURLRequestedDelayed(const KURL&, const KParts::URLArgs&)")
do | kurl, args|
		puts kurl.url
end

Both of the calls I checked and they are working.

The way this new methods work is quite simple:
it take the block passed and passes it to a new created "proxy" (an
instance of Qt::BlockInvocator) altogether with the arguments of the
signal. the BlockInvotator creates the slots "process" with the very
arguments of the signal so it fits perfectly. Then the signal will be
connect using the normal Qt::Object.connect to the slots "process" of
the instance of BlockInvocator.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: connect2Block.rb
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20060902/25deaa16/attachment.ksh>


More information about the Kde-bindings mailing list