Skip to content

Instantly share code, notes, and snippets.

@mydoghasworms
Created December 12, 2013 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mydoghasworms/7923856 to your computer and use it in GitHub Desktop.
Save mydoghasworms/7923856 to your computer and use it in GitHub Desktop.
Ruby and Qt; using 'qtbindings' example of using signals and slots, demonstrating how to use parameter-less, simple and class-parameter for sending signals.
require 'Qt'
# The class that will act as the receiver
class A < Qt::Object
slots :receive, 'receive_int(int)', 'receive_path(QString)'
def receive
puts 'event received'
end
def receive_int(i)
puts "received int #{i}"
end
def receive_path(path)
puts path
end
end
# Class that will act as the sender
# signal() creates the signal methods for us in the class
class B < Qt::Object
signals :give, 'give_int(int)', 'give_path(QString)'
end
# Necessary for any Qt app
app = Qt::Application.new(ARGV)
# Instantiate the classes
a = A.new
b = B.new
# Connect signals and slots globally
app.connect(b, SIGNAL(:give), a, SLOT(:receive))
app.connect(b, SIGNAL('give_int(int)'), a, SLOT('receive_int(int)'))
app.connect(b, SIGNAL('give_path(QString)'), a, SLOT('receive_path(QString)'))
# Testing emitting the signals
b.give
b.give_int(5)
b.give_path('a test string')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment