SIGNAL AND SLOT



  • I want to connect this two variables sampTime,sigFreq by using the spinbox or slider using the signal slot technique

    for ( int i=0; i<101; ++i)
    {
    x[i] = isampTime;
    y[i] = sin(2
    3.14sigFreqx[i]);
    }

    i tried something like this
    connect(ui->doubleSpinBox, SIGNAL(valueChanged(double)),sampFreq,SLOT(displayValue(double)));

    connect(ui->customPlot, SIGNAL(valueChanged(double)), ui->customPlot->graph(0),SLOT(valueChanged(double));

    PLS suggest how to do this



  • Did you take a look at "this":http://doc.qt.digia.com/qt/signalsandslots.html tutorial?

    You can connect only object which derive from QObject ( Since Qt5 if I know correctly it does no longer need to be QObject).

    but correct syntax:
    @connect(ui->doubleSpinBox, SIGNAL(valueChanged(double)), receiver, SLOT(methodName(double)));@

    Receiver can be this if your working in the same class (QMainWindow probably).
    When value in spin box is changed, it will be "sent" to you method. From there you can do further processing.



  • thanks for reply
    but what will come on the place of methodName() if i have to make a slot method myself because spinbox do not have any such methods

    [quote author="Jake007" date="1356776769"]Did you take a look at "this":http://doc.qt.digia.com/qt/signalsandslots.html tutorial?

    You can connect only object which derive from QObject ( Since Qt5 if I know correctly it does no longer need to be QObject).

    but correct syntax:
    @connect(ui->doubleSpinBox, SIGNAL(valueChanged(double)), receiver, SLOT(methodName(double)));@

    Receiver can be this if your working in the same class (QMainWindow probably).
    When value in spin box is changed, it will be "sent" to you method. From there you can do further processing. [/quote]



  • Yes.

    in your class
    @
    class MyMainWindow : QMainWindow
    {
    //...
    public slots:
    void onSpinBoxChange(double var); // make sure that arguments are the same as in the signals method.
    //...
    };

    void MyMainWindow::onSpinBoxChange(double var)
    {
    // Your code to execute when value is changed.
    }
    @



  • thanks a lot.

    [quote author="Jake007" date="1356777920"]Yes.

    in your class
    @
    class MyMainWindow : QMainWindow
    {
    //...
    public slots:
    void onSpinBoxChange(double var); // make sure that arguments are the same as in the signals method.
    //...
    };

    void MyMainWindow::onSpinBoxChange(double var)
    {
    // Your code to execute when value is changed.
    }
    @[/quote]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.