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 16 Jul 2018, 06:40 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 16 Jul 2018, 07:19 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

      A S 2 Replies Last reply 16 Jul 2018, 07:38
      4
      • S SGaist
        16 Jul 2018, 07:19

        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.

        A Offline
        A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on 16 Jul 2018, 07:38 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 23 Jul 2018, 06:21
        4
        • S SGaist
          16 Jul 2018, 07:19

          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 16 Jul 2018, 09:25 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
          • V Offline
            V Offline
            VRonin
            wrote on 16 Jul 2018, 09:55 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
            • A aha_1980
              16 Jul 2018, 07:38

              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 23 Jul 2018, 06:21 last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 23 Jul 2018, 06:39 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

                6/7

                23 Jul 2018, 06:21

                • Login

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