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 while loop using some conditional check?
Forum Update on Monday, May 27th 2025

how to break while loop using some conditional check?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 3.0k 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 VRonin
    #1

    Hi
    I am using SQLite database to fetch the data in Qt and then I am printing that data simultaneosly.
    Kindly go through the process

    (e.g.

       while(studentList.next())
                     {  studentList("SELECT Name, address FROM class  WHERE Roll No = some variable;
                      Name=studentList.value(0).toString();   
                      address=studentList.value(1).toString();   
    
    
     //********   simultaneously I am printing this data (in a string) through GPIO pins by setting them HIGH accordingly.....    ******  //
                                      
    
    {
    
    
          ------  PRINTING MODULE ------
    
     }
                     }  
    

    During printing, GUI goes in a hang state .....
    Now I want to break this printing in between as per my wish!
    Any way to do it!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Depending on how you do that printing and more specifically the time it takes, you should rather offload the work to a secondary thread.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      aha_1980A S 2 Replies Last reply
      4
      • SGaistS SGaist

        Hi,

        Depending on how you do that printing and more specifically the time it takes, you should rather offload the work to a secondary thread.

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

        If the time the printing module takes is rather short, it may already be enough to break the loop and put the loops body in a QTimers slot that you call regularly in short intervalls.

        So in the time between the timers slots Qt has time to execute it's event loop.

        Qt has to stay free or it will die.

        S 1 Reply Last reply
        4
        • SGaistS SGaist

          Hi,

          Depending on how you do that printing and more specifically the time it takes, you should rather offload the work to a secondary thread.

          S Offline
          S Offline
          SHUBHAM SINGH RAO
          wrote on last edited by SHUBHAM SINGH RAO
          #4

          @SGaist Right now I m in the learning stage of threading..so a bit difficult for me to apply it directly
          Could u plz quote an example which can be referred?

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            See "Staying Responsive During Intensive Processing" page 171 (189 of the pdf) of C++ GUI Programming with Qt 4

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            4
            • aha_1980A aha_1980

              If the time the printing module takes is rather short, it may already be enough to break the loop and put the loops body in a QTimers slot that you call regularly in short intervalls.

              So in the time between the timers slots Qt has time to execute it's event loop.

              S Offline
              S Offline
              SHUBHAM SINGH RAO
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Your loop blocks the event loop so it can't process anything.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                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