Class: Qt::Timer

Inherits:
Object show all
Defined in:
lib/rui/toolkits/qtbase/qt.rb

Class Method Summary collapse

Class Method Details

.every(interval, &blk) ⇒ Object

Execute the given block every interval milliseconds and return a timer object. Note that if the timer is garbage collected, the block will not be executed anymore, so the caller should keep a reference to it for as long as needed. To prevent further invocations of the block, use QTimer#stop.



341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/rui/toolkits/qtbase/qt.rb', line 341

def self.every(interval, &blk)
  time = Qt::Time.new
  time.restart
  
  timer = new
  timer.connect(SIGNAL('timeout()')) { blk[time.elapsed] }
  timer.start(interval)
  # return the timer, so that the caller
  # has a chance to keep it referenced, so
  # that it is not garbage collected
  timer
end

.in(interval, target = nil, &blk) ⇒ Object

Execute the given block after interval milliseconds. If target is specified, the block is invoked in the context of target.



358
359
360
361
362
# File 'lib/rui/toolkits/qtbase/qt.rb', line 358

def self.in(interval, target = nil, &blk)
  single_shot(interval,
              Qt::BlockInvocation.new(target, blk, 'invoke()'),
              SLOT('invoke()'))
end