Reputation: 131
I have two Button: play and pause. And I slider bar.
I want to press the player to change the position of the slide until an event is issued, or the pause button is pressed. For this reason I'm using QEventLoop.
void MainWindow::slider()
{
for(min_value = ui->horizontalSlide->value(); min_value <= max_value; min_value++){
//msleep(2000);
ui->horizontalSlide->setValue(min_value);
}
}
void MainWindow::on_playButton_clicked()
{
QEventLoop loop2;
QObject::connect(this, SIGNAL(quitLoop()), &loop2... ?);
loop2.exec();
}
void MainWindow::on_pauseButton_clicked()
{
emit quitLoop();
}
But I'm not sure how to connect the QEventLoop to the on_playButton_clicked function.... Any examples or advice?
Thank you very much!
Upvotes: 1
Views: 886
Reputation: 244093
It is not necessary to create an eventLoop for this case, just use a QTimer:
*.h
private:
QTimer *timer
.cpp
MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent)
{
[...]
timer = new QTimer(this);
connect(timer, &QTimer::timeout, [this](){
int value = ui->horizontalSlide->value();
ui->horizontalSlide->setValue(value+1);
if(ui->horizontalSlide->value() == ui->horizontalSlide->maximum())
timer->stop();
});
}
void MainWindow::on_playButton_clicked(){
timer->start(2000);
}
void MainWindow::on_pauseButton_clicked()
{
timer->stop();
}
Upvotes: 2