From: Stefano Crocco Date: 2009-01-21T19:02:57+09:00 Subject: Re: Using qui rather than rbuic for qtdesigner .ui files Alle mercoledì 21 gennaio 2009, Stefano Crocco ha scritto: > Alle lunedì 19 gennaio 2009, David Brunell ha scritto: > > One other question...what about Qt4?  I think I need rbuic4 if I am > > going to pre-compile the ui.  Is there a qui4 for dynamic loading? > > The following should work using a recent svn revision from kdebindings. > However, it doesn't because findChild fails. I think it's a bug and I'll > try to contact the developers to > > require 'Qt4' > require 'qtuitools' > > class Dlg < Qt::Dialog > > slots 'test()' > > def initialize parent = nil > super > file = Qt::File.new File.expand_path('~/temp/test_ui.ui') > file.open(Qt::File::ReadOnly) > loader = Qt::UiLoader.new > @widget = loader.load file, self > file.close > self.layout = Qt::VBoxLayout.new self > layout.add_widget @widget > @close_btn = @widget.findChild(Qt::PushButton, 'close_btn') > @test_btn = @widget.findChild(Qt::PushButton, 'test_btn') > connect @close_btn, SIGNAL('clicked()'), Qt::Application.instance, > SLOT('close()') > connect @test_btn, SIGNAL('clicked()'), self, SLOT('test()') > end > > def test > puts "testing" > end > > end > > app = Qt::Application.new ARGV > dlg = Dlg.new > dlg.exec > app.exec > > Stefano My previous code contained an error: the clicked() signal of @close_btn should be connected to the quit() slot of Qt::Application.instance, not to the close() signal (which it doesn't exist). Also, to work around the bug I spoke about, it's enough to replace Qt::PushButton with Qt::Object in the two calls to findChild. Stefano