I am working on a math trainer project. So, I must display int values from the array to QLCDNumber with delay. I used QTimer::singleshot but it delays only before the first number. Here is my code. What is the problem?
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLCDNumber>
#include <QTimer>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
int arr[] = {100,2,21,12};
for (int i = 0;i<4;i++) {
QTimer::singleShot(2000,
this,
[=]{ ui->lcdNumber->display(arr[i]);
});
}
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLCDNumber>
#include <QTimer>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
int arr[] = {100,2,21,12};
for (int i = 0;i<4;i++) {
QTimer::singleShot(2000,this,[=]{
ui->lcdNumber->display(arr[i]);
});
}
}
To copy to clipboard, switch view to plain text mode
I can see only 12.photo_2019-03-25_22-41-10.jpg
Bookmarks