[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

I just love RUBY programming

t3chn0n3rd

3/2/2008 2:28:00 PM

#!/usr/bin/env ruby
require 'Qt'


class MyWidget < Qt::Widget
slots 'but_clie()'


def initialize(parent=nil)
super(parent)
@table = Qt::Table.new(10,10,self)

connect(@table,SIGNAL('clicked()'),self,SLOT('but_clie
()'))
end


def but_clie
puts "clicked"
end
end


2 Answers

Phlip

3/2/2008 3:08:00 PM

0

t3chn0n3rd wrote:

> require 'Qt'

> class MyWidget < Qt::Widget
> slots 'but_clie()'

> def initialize(parent=nil)
> super(parent)
> @table = Qt::Table.new(10,10,self)
>
> connect(@table,SIGNAL('clicked()'),self,SLOT('but_clie
> ()'))
> end

That's kind'a feeb compared to what Ruby can really do.

From the top: Qt uses C++ for highly event-driven GUIs. This requires adding
two new keywords to C++ - slots and signals. They achieve dynamic typing and
event hooks.

Your code is just a slavish translation of slots and signals to Ruby.
However, Ruby already has dynamic typing, and a superior event system using
block closures. So I wouldn't be surprised if this Ruby/Qt library also
provided a simpler mechanism using raw Ruby, and hiding the actual slots and
signals on the inside.

For extra credit - write unit tests for your GUI code!

--
Phlip


richard.j.dale@gmail.com

3/2/2008 6:01:00 PM

0

On Mar 2, 2:28 pm, t3chn0n3rd <darrin_al...@japan.com> wrote:
> #!/usr/bin/env ruby
> require 'Qt'
>
> class MyWidget < Qt::Widget
> slots 'but_clie()'
>
> def initialize(parent=nil)
> super(parent)
> @table = Qt::Table.new(10,10,self)
>
> connect(@table,SIGNAL('clicked()'),self,SLOT('but_clie
> ()'))
> end
>
> def but_clie
> puts "clicked"
> end
> end
Well there isn't actually a Qt widget called Qt::Table, do you mean
Qt::TableWidget ?

You can connect a block to a signal like this if you prefer:

#!/usr/bin/env ruby
require 'Qt4'

class MyWidget < Qt::Widget
def initialize(parent=nil)
super(parent)
@table = Qt::TableWidget.new(10, 10, self)

connect(@table, SIGNAL('cellClicked(int,int)'), self) do |r, c|
puts "cellClicked r: #{r} c: #{c}"
end
end
end

-- Richard