Twitter GitHub Facebook Instagram

Daniel Irvine on building software

Timed events with Ruby and qtbindings

3 June 2014

In the Qt world, events are raised via signals and are handled by slots. Raising events at specific time intervals must be done through this mechanism: the timeout() signal is the one we’re after.

With the latest qtbindings for Ruby you can reference signals and slots with the more Ruby-esque symbols:

timer =
connect(timer, SIGNAL(:timeout), self, SLOT(:time_up))

The call to class method slots then becomes

slots :time_up

You can tie this in with a Ruby Proc to build an abstraction around the Qt framework.

class MyWidget < Qt::Widget

  attr_writer :on_time_up
  slots :time_up

  def initialize
    @timer =
    connect(@timer, SIGNAL(:timeout), self, SLOT(:play))

  def time_up

About the author

Daniel Irvine is a software craftsman at 8th Light, based in London. These days he prefers to code in Clojure and Ruby, despite having been a C++ and C# developer for the majority of his career.

For a longer bio please see To contact Daniel, send a tweet to @d_ir or use the comments section below.

Twitter GitHub Facebook Instagram