PDA

View Full Version : Problem with SpinBox signals and slots



ramstormrage
30th April 2008, 03:51
Hello and good day.

Id like to seek help regarding a dialog that doesnt obey its signals and slots connections.
I have this code for the dialog connecting different spinboxes,



connect(mnhSpinBox, SIGNAL(valueChanged(int)), mxhSpinBox, SLOT(setValue(int)));
connect(mnsSpinBox, SIGNAL(valueChanged(int)), mxsSpinBox, SLOT(setValue(int)));


Now when i build my program, it doesnt fulfill its intended purpose which is to update the value of the other spin box.

BUT, when I connect the signals and slots via the designer it works. Now I have built other dialogs but I didnt encounter any problems like this.

Any help would be greatly appreciated.

P.S.: Ive read the FAQ about the signals and slots but it didnt help me.

jpn
30th April 2008, 07:27
Could you provide a minimal compilable example which reproduces the problem?

ramstormrage
1st May 2008, 02:28
Ok. I forgot to tell that I am running QT4 for Windows.
I uploaded two versions,
- in the folder sample contains the .ui file that has no signals set in the designer
- int the folder sample2 contains the .ui file that has signals and slots set in the designer

Thank you for looking into them..

mitro
1st May 2008, 11:29
Your code does not use isolateDialog at all. The dialog instantiation is not correct. You should not create QDialog and set Ui::isolateDialog for it. You are to create isolateDialog instead. So remove the following lines:


Ui::isolateDialog ui;
QDialog *dialog = new QDialog;
ui.setupUi(dialog);

And just add


isolateDialog *dialog = new isolateDialog;

You also have a mistake in your dialog .cpp file.


connect(minsatSpinBox, SIGNAL(valueChanged(int)), minhueSpinBox, SLOT(setValue(int)));
must be replaced with

connect(minsatSpinBox, SIGNAL(valueChanged(int)), maxsatSpinBox, SLOT(setValue(int)));

The reason why your code works when you make connections in QDesigner is that QDesigner connects signals and slots in the constructor of Ui::isolateDialog.

ramstormrage
2nd May 2008, 01:45
Ok that was very informative.

Thank you very much for the help. I appreciate it.