Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to break the loop when running the loop.
Forum Updated to NodeBB v4.3 + New Features

how to break the loop when running the loop.

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 356 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ramkumar Mohan
    wrote on 2 Jan 2023, 05:22 last edited by
    #1

    This is my code,

    I have started the timer as initially and set the pushbutton to run on it and when pushbutton 2 is clicked the timer will stop but when the loop is running when pushbutton 2 is clicked it is not working. The button I clicked runs after the loop reaches target 100. How to fix this

    MainWindow.CPP

     MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
     ui(new Ui::MainWindow)
     {
          ui->setupUi->(this);
    
          Functionstart = new QTimer(this);
          connect(Functionstart ,SIGNAL(timeout()) , this ,SLOT(on_pushButton_clicked()));
          Functionstart->start(1000);
     }
    
     void MainWindow::on_pushButton_clicked()
     {
          for(int i=0;i<=100;i++)
          {
               if(i==100)
               {
                  ui->stackedWidget->setCurrentIndex(2);
               }
               else
               {
                   qDebug()<<"Loop Running";
                }
           }
      }
    
      void MainWindow::on_pushButton_2_clicked()
      {
           Functionstart->stop();
      }
    

    Thanks in advance,

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on 2 Jan 2023, 06:36 last edited by ChrisW67 1 Feb 2023, 06:39
      #2

      The Qt event loop is necessary to dispatch the timeout() signal. The on_pushbutton_clicked() slot will not return to the Qt event loop until on_pushButton_clicked() finishes doing 101 seemingly pointless loops setting the stacked widget current page on the last.

      Perhaps you can explain what you are trying to achieve.

      1 Reply Last reply
      3
      • K Offline
        K Offline
        Kent-Dorfman
        wrote on 3 Jan 2023, 02:36 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0

        1/3

        2 Jan 2023, 05:22

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved