signal interval question
Solved
General and Desktop
-
I want to change my signal to change value in an interval.
For example, I want to update the valueSpinBox when i have changed the horizontalSliders.connect(horizontalSliders, &SlidersGroup::valueChanged, [=](int value){ this->ui->valueSpinBox->setValue(value); });
However, I want to change the value in an interval 200ms intead of changing them real time. Is it possible? Thank you.
-
@clementNg You will need to use QTimer
For example, if you want to do the actual change 200ms after signal was emitted you can use https://doc.qt.io/qt-5/qtimer.html#singleShot -
@jsulm
Thank you for your reply. Do I need to disconnect the signal and connect again after the interval? Would you mind to give a simple example? Thanks.QTimer::singleShot(200, [=](){ // connect my horizontalSliders slot here? // disconnect the slot after the action? });
-
connect(horizontalSliders, &SlidersGroup::valueChanged, [=](int value){ QTimer::singleShot(200, [=](){ this->ui->valueSpinBox->setValue(value); }); });
No need to disconnect as singleShot does not connect anything.