0

I create connections between widged in the constructor and also initialize them. But the connect not working (inside the methode).

Code says alot:

MyApp::MyApp(QWidget *parent) : QMainWindow(parent)
{
    ui.setupUi(this);

    // slider to spinbox
    connect(ui.slider, SIGNAL(valueChanged(int)), ui.spinbox, SLOT(setValue(int)));

    // SIGNAL To SLOT not called
    ui.slider->setValue(2);
    // I have to set this also:
    ui.spinbox->setValue(2);
}
Viatorus
  • 1,804
  • 1
  • 18
  • 41
  • 1
    If you used Qt creator, what's the error message shown in application output? Simply "**not working**" doesn't provide enough information. Besides, your code looks weird: `connect()` use pointer as arguments, which brings `ui.slider` and `ui.sinbox` unreasonable. If the `ui` file are created automatically, they should have been `ui->slider` and `ui->spinbox`. – Tay2510 Jul 08 '14 at 17:18

1 Answers1

0

Have you tried doing

connect(ui.slider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));

and have the slot setValue(int) update the spinbox when the slider is changed?

If you need it to go both ways, you will need to make two connections. One to connect a signal/slot to the slider, and one to connect a signal/slot to the spinbox.

Also, are you getting any errors?

bmartin
  • 675
  • 5
  • 12