From: Stefano Crocco Date: 2009-05-12T15:17:11+09:00 Subject: Re: (mandriva,eclipse,Qt) elementary problem : signals and slots On Monday 11 May 2009, lolveley wrote: > |hi, > | > |I would like to make a little program using Qt : it's a displayer / > |converter between farenheit and celsius degrees. > |I also want to use QtDesigner. > | > |I made a little widget with QtDesigner, and this widget contains two > |dials(dial and dial_2) and two spinboxes(kind of textboxes) (spinbox and > |spinbox_2). > |There are some connections : see below for the ruby file I obtained with > |the tool rbuic4 (which converts the ".ui" file into ".rb"). > |my problem is this : I want that some changes made in dial_2 modify dial > |(and then spinbox), eg : > | 0 celsius degrees => 32 farenheit degrees. > | > |here is the file made by rbuic4 and after this my try to modify the slot > |setValue (but it doesn't run: the value of dial is always the same as > |the one of dial_2. I don't know why it doesn't work, as I never used the designer to make signal/slot connections. I'd say it should work, but there might be some limitations which I'm not aware of. My suggestion is to use a custom widget class instead of a generic Qt::Widget and to implement the slot which converts the values there. Here's how the tmp_dsc_form.rb could look like: require 'Qt4' require 'temp.rb' class MyWidget < Qt::Widget slots 'change_values(int)' def initialize super @ui = Ui_Form.new @ui.setupUi self connect @ui.dial_2, SIGNAL('valueChanged(int)'), self, SLOT('change_values(int)') end def change_values val new_value = (1.8*val+32).to_i @ui.spinBox.value = new_value @ui.dial.value = new_value end end une_appli=Qt::Application.new(ARGV) un_wdg = MyWidget.new un_wdg.show une_appli.exec Of course, if you use this you can remove the connections made from the designer. I hope this helps Stefano