From: Stefano Crocco Date: 2009-01-14T18:02:45+09:00 Subject: Re: Using qui rather than rbuic for qtdesigner .ui files Alle mercoledì 14 gennaio 2009, David Brunell ha scritto: > I'm trying to load .ui files at runtime using the qui extension and > WidgetFactory rather than pre-translating the .ui XML file to ruby with > rbuic. Here's a simple program: > > require 'Qt' > require 'qui' > a = Qt::Application.new(ARGV) > w = QUI::WidgetFactory.create "sampledialog.ui" > w.show() > a.connect(a, SIGNAL('lastWindowClosed()'), a, SLOT('quit()')) > a.exec() > > This works just fine in that it dynamically loads and presents the .ui > file as a window. However, how do I connect signals and slots? I > understand the process of method override when doing it the rbuic way, > but this doesn't seem to be working with WidgetFactory. The signals and > slots (but not their handling) are defined in the .ui file. Could > someone give this noob an example of how to implement a slot method? I > tried looking at some C++ examples, but I'm just not making the > connection to ruby. The .ui file is below. It just has two buttons, > Test and Close. > > Thanks, > > David Not tested, because I'm using Qt 4 while, I think, you're using Qt 3. The idea is to create a custom widget class and to add the widget returned by WidgetFactory.create as child widget. You shouldn't define custom slots in the ui file, since there's no way to implement them. Any custom slot you'd define in the ui file is instead defined in the custom widget. Here's a simple example which should work: require 'Qt' require 'qui' class MainWidget < Qt::Widget slots 'test()' def initialize @widget = QUI::WidgetFactory.create "sampledialog.ui" self.layout = Qt::VBoxLayout.new self.layout.add_widget @widget connect @widget.child('testButton'), SIGNAL('clicked()'), self, SLOT('test()') end def test puts "test button clicked" end end app = Qt::Application.new ARGV w = MainWidget.new w.show a.connect(a, SIGNAL('lastWindowClosed()'), a, SLOT('quit()')) a.exec I hope this helps Stefano