Re: (mandriva,eclipse,Qt) elementary problem : signals and slots



hello,

thank you richard and stefano for your answers.
I'm afraid I haven't well understood the system of slots, if I want to
rewrite a slot - say setValue(int) - of a dial what can I put in this
method? I have to put a statement telling the slot to modify graphically
the widget, but I don't think it is possible.

I think _ but I'm not sure _ I have understood the solution of richard :
it is to create a class with a slot (for example setValue) which receive
the value in degree, and this slot emit a signal (here
dial.setValue(int)) which send the converted value (in Farenheit).

is it this?

lolveley.



richard.j.dale@xxxxxxxxx a écrit :
On May 12, 7:17 am, Stefano Crocco <stefano.cro...@xxxxxxxx> wrote:

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'm not sure if this solves the problem of making the changes bi-
directional because if you use the 'valueChanged(int)' signal, as you
will end up with a loop because each dial will try to change the
other.

I think the original rbuic4 generated code was nearly correct, but it
should use 'sliderMoved(int)' signals in one dial connected to
'setValue(int)' in the other dial because that would loop. And it
needs an extra connection so that @dial_2 is changed when @dial is
changed.

Qt::Object.connect(@dial, SIGNAL('sliderMoved(int)'), @dial_2, SLOT
('setValue(int)'))
Qt::Object.connect(@dial_2, SIGNAL('sliderMoved(int)'), @dial, SLOT
('setValue(int)'))

But that wouldn't convert the values. So instead it needs an
intermediate Qt::Object (doesn't need to be a Qt::Widget) to convert
the values as Stefano suggests.


-- Richard









___________________________________________________________________________
Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son interface révolutionnaire.
http://fr.mail.yahoo.com


.



Relevant Pages