Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    India
    2
    3
    1081
    Loading More Posts
    • 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
      SHUBHAM SINGH RAO last edited by 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_1980 2 Replies Last reply Reply Quote 0
      • aha_1980
        aha_1980 Lifetime Qt Champion @SHUBHAM SINGH RAO last edited by

        @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 Reply Quote 1
        • aha_1980
          aha_1980 Lifetime Qt Champion @SHUBHAM SINGH RAO last edited by

          @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 Reply Quote 2
          • First post
            Last post