####
# needed for ruby < 1.9

class Object
	def instance_exec(*args, &block)
		mname = "__instance_exec_#{Thread.current.object_id.abs}"
		class << self; self end.class_eval{ define_method(mname, &block) }
		begin
			ret = send(mname, *args)
		ensure
			class << self; self end.class_eval{ undef_method(mname) } rescue
				nil
		end
		ret
	end
end

####

module Qt
	class Object
		
		def Object.connect2Block(src, signal, target, &block)
			signalVars = (signal =~ /\((.*)\)/) ? $1 : ""
			Qt::Object.connect(
				src, signal,
				BlockInvocation.new(target, block, signalVars), SLOT("process(#{signalVars})")
			)
		end
	end

	class BlockInvocation < Qt::Object
		def initialize(target,block, args)
			super(target)
			self.class.slots "process(#{args})"
			@target = target
			@toCall = block
		end

		def process(*vars)
			@target.instance_exec(*vars, &@toCall)
		end
	end
end