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.

how to break the loop when running the loop.

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 437 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.
  • Ramkumar MohanR Offline
    Ramkumar MohanR Offline
    Ramkumar Mohan
    wrote on 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 last edited by ChrisW67
      #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
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0

        • Login

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