Hi Poornima:

Thanks for the good discussion about QtRuby and
signal/slot mechanism.

In QtRuby, when connecting signals and slots,
the Qt style syntax has to be used.

The method names and arguments are passed as
'strings' wrapped by either SIGNAL() or SLOT().

Please see the example below.

#!/usr/bin/ruby -w

require 'Qt'

class MyWidget < Qt::Widget

        slots 'onclick()'

        def initialize(parent=nil)
                super(parent)

                @label  = Qt::Label.new(self)
                @button = Qt::PushButton.new(self)
                @layout = Qt::VBoxLayout.new(self)
                @layout.addWidget(@label)
                @layout.addWidget(@button)
                @clicked_times = 0

                @label.setText("button clicked " + @clicked_times.to_s())

                @button.setText("Button")

                connect(@button, SIGNAL('clicked()'),
                self,    SLOT('onclick()'))
        end

        def onclick()
                @clicked_times += 1
                @label.setText("button clicked " + @clicked_times.to_s())
        end


end

a = Qt::Application.new(ARGV)
m = MyWidget.new()
a.setMainWidget(m)
m.show()
a.exec()


Please do share your thoughts and observations.


thanks
Saifi.

Reply via email to