Qt4 designer, custom slots and rbuic4

Kopija iz strani: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/241780
Da ne pozabim!!!

> Has anybody had any luck implementing custom slots in ruby without
> changing the output of rbuic4?  Everything I have tried results in
> segfaults and superclass mismatch errors.

I’ve done this:

  1. Ustvari custom_widget_base.ui z Designerjem (predpostavimo, da se forma imenuje CustomWidgetBase in da vsebuje en sam push button z imenom ‘push_button‘)
  2. Zaženi rbuic4 na datoteko, da dobiš custom_widget_base.rb. Ta file vsebuje razred z imenom Ui_CustomWidgetBase, iz katerega je izpeljan razred CustomWidgetBase, ki ga vsebuje modul Ui.
  3. Ustvari datoteko custom_widget.rb z naslednjo vsebino:
require 'custom_widget_base.rb' #require the rbuic4-generated file
class CustomWidget < Qt::Widget

slots 'button_pressed()'

def initialize parent=nil
super #call Qt::Widget constructor
@base=Ui::CustomWidgetBase.new
@base.setupUI self #this is where the widget construction happen
connect @base.push_button,SIGNAL('pressed()'),self,SLOT('button_pressed())
end

def button_pressed
Qt::MessageBox.information self, 'App', 'The button has been pressed'
end

end

Share if thou wilt!

shares
%d bloggers like this: