# Qt4 designer, custom slots and rbuic4

**URL:** <https://www.ruby-forum.com/t/qt4-designer-custom-slots-and-rbuic4/87629>\
**Category:** Ruby\
**Created:** [March 4, 2007, 4:54pm UTC](https://www.ruby-forum.com/t/qt4-designer-custom-slots-and-rbuic4/87629 "2007-03-04T16:54:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [March 4, 2007, 4:54pm UTC](https://www.ruby-forum.com/t/qt4-designer-custom-slots-and-rbuic4/87629/1 "2007-03-04T16:54:30Z")

</div>

Hello everyone,

I just started looking at trying to write some Qt stuff in ruby. I  
whipped up a quick widget in designer to see how the whole process  
works. When it came time to connect a button to a custom slot I got  
stuck. The docs on the internet that deal with designer are all qt3  
based. The search button on this forums website is broken, so sorry if  
this has been brought up already.

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.

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [March 4, 2007, 5:18pm UTC](https://www.ruby-forum.com/t/qt4-designer-custom-slots-and-rbuic4/87629/2 "2007-03-04T17:18:17Z")

</div>

Alle domenica 4 marzo 2007, Chris ha scritto:

> changing the output of rbuic4? Everything I have tried results in  
> segfaults and superclass mismatch errors.

I’ve done this:

- create a custom\_widget\_base.ui with designer (suppose the form name is  
CustomWidgetBase and that it contains a single push button,  
named ‘push\_button’)
- run rbuic4 on the file, getting custom\_widget\_base.rb. This file  
contains a  
class called Ui\_CustomWidgetBase, from which a class called  
CustomWidgetBase,  
contained in a module called Ui, is derived.
- create the file custom\_widget.rb with the following contents:

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

As to connecting to custom slots directly from Qt designer, I haven’t  
been  
able to find out how to create custom slots in the designer. While in  
the Qt3  
version there was a dialog to do that, it seems to have disappeared in  
the  
new version. Even the examples in the designer manual only show  
connecting an  
existing signal to an existing slot.

I hope this helps.

Stefano

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [March 4, 2007, 7:19pm UTC](https://www.ruby-forum.com/t/qt4-designer-custom-slots-and-rbuic4/87629/3 "2007-03-04T19:19:32Z")

</div>

> I hope this helps.
> 
> Stefano

Yes it did. Thank you Stefano, everything is working now.

Chris
