Stefano Crocco
1/14/2009 9:03:00 AM
Alle mercoled=C3=AC 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 =3D Qt::Application.new(ARGV)
> w =3D 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 i=
dea=20
is to create a custom widget class and to add the widget returned by=20
WidgetFactory.create as child widget. You shouldn't define custom slots in =
the=20
ui file, since there's no way to implement them. Any custom slot you'd defi=
ne=20
in the ui file is instead defined in the custom widget. Here's a simple=20
example which should work:
require 'Qt'
require 'qui'
class MainWidget < Qt::Widget
=20
slots 'test()'
=20
def initialize
@widget =3D QUI::WidgetFactory.create "sampledialog.ui"
self.layout =3D Qt::VBoxLayout.new
self.layout.add_widget @widget
connect @widget.child('testButton'), SIGNAL('clicked()'), self,=20
SLOT('test()')
end
=20
def test
puts "test button clicked"
end
=20
end
app =3D Qt::Application.new ARGV
w =3D MainWidget.new=20
w.show
a.connect(a, SIGNAL('lastWindowClosed()'), a, SLOT('quit()'))
a.exec
I hope this helps
Stefano