Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. India
  4. How to prevent GUI from hanging while allowing 2nd operation to be performed alongwith 1st operation!
Forum Update on Monday, May 27th 2025

How to prevent GUI from hanging while allowing 2nd operation to be performed alongwith 1st operation!

Scheduled Pinned Locked Moved Unsolved India
3 Posts 2 Posters 1.3k Views
  • 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.
  • S Offline
    S Offline
    SHUBHAM SINGH RAO
    wrote on last edited by SHUBHAM SINGH RAO
    #1

    Here I am explaining my problem statement in detail and the efforts I have put so far
    0_1532323806601_cropped.png

    Problem Statement : During printing if 'Stop Printing' pushbutton is pressed, the printing should stop at that moment!

    *My Work * -

    1. StartPrinitng_Pressed :

       void MainWindow :: on_StartPrinitng_Pressed()
       
       {
              while(studentList.next())
        {  studentList("SELECT Name, address FROM class  WHERE Roll No = some    variable")
                 
        Name=studentList.value(0).toString();   
        address=studentList.value(1).toString();   
      
        QTimer:: singleShot(1000,this,SLOT(StopNow()));   //calling stopNow function
      
      if(StopPrintingNow==0)
        {  //**   I am printing the fetched data (in a string)  by setting GPIO pins  HIGH      **//  }
      
       else if(StopPrintingNow==1)
       {    //**  I have reset all serials ports; Break;   **//  }
          
      }
      }
      
    2. StopPrinting_Pressed :

      void MainWindow::on_StopPrinting_Pressed()
       {StopPrintingNow=1;} 
      
    3. StopNow Function Declaration :

       void MainWindow::StopNow() 
         {
      if(StopPrintingNow==1)
         {   //**  I have reset all serials ports; Break;   **// }
      else if(StopPrintingNow==0)
        { QTimer::singleShot(1000,this,SLOT(on_startPrinting_pressed())); }
         }
      

    Flow of program execution : As and when "StartPrinting" pushbutton is pressed, the query shown in my question executes which fetches data from database and perform simultaneous printing.

    Problem Faced -
    1.GUI is getting hanged while printing, hence StopPrinting button doesn't respond.
    2. Qtimer is not calling "StopNow function " while printing (though I have called it at correct position)

    aha_1980A 2 Replies Last reply
    0
    • S SHUBHAM SINGH RAO

      Here I am explaining my problem statement in detail and the efforts I have put so far
      0_1532323806601_cropped.png

      Problem Statement : During printing if 'Stop Printing' pushbutton is pressed, the printing should stop at that moment!

      *My Work * -

      1. StartPrinitng_Pressed :

         void MainWindow :: on_StartPrinitng_Pressed()
         
         {
                while(studentList.next())
          {  studentList("SELECT Name, address FROM class  WHERE Roll No = some    variable")
                   
          Name=studentList.value(0).toString();   
          address=studentList.value(1).toString();   
        
          QTimer:: singleShot(1000,this,SLOT(StopNow()));   //calling stopNow function
        
        if(StopPrintingNow==0)
          {  //**   I am printing the fetched data (in a string)  by setting GPIO pins  HIGH      **//  }
        
         else if(StopPrintingNow==1)
         {    //**  I have reset all serials ports; Break;   **//  }
            
        }
        }
        
      2. StopPrinting_Pressed :

        void MainWindow::on_StopPrinting_Pressed()
         {StopPrintingNow=1;} 
        
      3. StopNow Function Declaration :

         void MainWindow::StopNow() 
           {
        if(StopPrintingNow==1)
           {   //**  I have reset all serials ports; Break;   **// }
        else if(StopPrintingNow==0)
          { QTimer::singleShot(1000,this,SLOT(on_startPrinting_pressed())); }
           }
        

      Flow of program execution : As and when "StartPrinting" pushbutton is pressed, the query shown in my question executes which fetches data from database and perform simultaneous printing.

      Problem Faced -
      1.GUI is getting hanged while printing, hence StopPrinting button doesn't respond.
      2. Qtimer is not calling "StopNow function " while printing (though I have called it at correct position)

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @SHUBHAM-SINGH-RAO

      Hi, I think the SQL query is not your problem, it should be fast.

      Your problem is that you transmit the whole serial data during the slot. In this time the event loop is blocked and therefore the stop button is not working.

      Two possibilities:

      1. Only send some characters at a time, and then send the next chars in a timer slot, until all chars are sent.
      2. Move the whole serial sending into a second thread

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      1
      • S SHUBHAM SINGH RAO

        Here I am explaining my problem statement in detail and the efforts I have put so far
        0_1532323806601_cropped.png

        Problem Statement : During printing if 'Stop Printing' pushbutton is pressed, the printing should stop at that moment!

        *My Work * -

        1. StartPrinitng_Pressed :

           void MainWindow :: on_StartPrinitng_Pressed()
           
           {
                  while(studentList.next())
            {  studentList("SELECT Name, address FROM class  WHERE Roll No = some    variable")
                     
            Name=studentList.value(0).toString();   
            address=studentList.value(1).toString();   
          
            QTimer:: singleShot(1000,this,SLOT(StopNow()));   //calling stopNow function
          
          if(StopPrintingNow==0)
            {  //**   I am printing the fetched data (in a string)  by setting GPIO pins  HIGH      **//  }
          
           else if(StopPrintingNow==1)
           {    //**  I have reset all serials ports; Break;   **//  }
              
          }
          }
          
        2. StopPrinting_Pressed :

          void MainWindow::on_StopPrinting_Pressed()
           {StopPrintingNow=1;} 
          
        3. StopNow Function Declaration :

           void MainWindow::StopNow() 
             {
          if(StopPrintingNow==1)
             {   //**  I have reset all serials ports; Break;   **// }
          else if(StopPrintingNow==0)
            { QTimer::singleShot(1000,this,SLOT(on_startPrinting_pressed())); }
             }
          

        Flow of program execution : As and when "StartPrinting" pushbutton is pressed, the query shown in my question executes which fetches data from database and perform simultaneous printing.

        Problem Faced -
        1.GUI is getting hanged while printing, hence StopPrinting button doesn't respond.
        2. Qtimer is not calling "StopNow function " while printing (though I have called it at correct position)

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @SHUBHAM-SINGH-RAO

        And please don't cross post!

        This is exactly the same as https://forum.qt.io/topic/92674/how-to-break-while-loop-using-some-conditional-check/6

        Closing this one.

        Qt has to stay free or it will die.

        1 Reply Last reply
        2

        • Login

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