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?
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QLCDNumber>
  4. #include <QTimer>
  5.  
  6. MainWindow::MainWindow(QWidget *parent) :
  7. QMainWindow(parent),
  8. ui(new Ui::MainWindow)
  9. {
  10. ui->setupUi(this);
  11. }
  12.  
  13. MainWindow::~MainWindow()
  14. {
  15. delete ui;
  16. }
  17.  
  18. void MainWindow::on_pushButton_clicked()
  19. {
  20. int arr[] = {100,2,21,12};
  21. for (int i = 0;i<4;i++) {
  22. QTimer::singleShot(2000,this,[=]{
  23. ui->lcdNumber->display(arr[i]);
  24. });
  25. }
  26. }
To copy to clipboard, switch view to plain text mode 

I can see only 12.photo_2019-03-25_22-41-10.jpg