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_up" single methoid / function...
Forum Updated to NodeBB v4.3 + New Features

How to "break_up" single methoid / function...

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 470 Views 3 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    As of now I have a single (test) function / method which includes several time consuming - hardware dependent - tasks.
    The "result" of this - I get GUI update AFTER all tasks are finished.

    I like to have GUI update AFTER EACH task is done, or at minimum - some kind of status display - located at "master GUI " after each task.

    Any suggestion on how to realize this ?

    S 1 Reply Last reply
    0
    • S Offline
      S Offline
      SamiV123
      wrote on last edited by
      #2

      do your work in a background thread(s), post some status update/event to the main thread

      1 Reply Last reply
      0
      • A Anonymous_Banned275

        As of now I have a single (test) function / method which includes several time consuming - hardware dependent - tasks.
        The "result" of this - I get GUI update AFTER all tasks are finished.

        I like to have GUI update AFTER EACH task is done, or at minimum - some kind of status display - located at "master GUI " after each task.

        Any suggestion on how to realize this ?

        S Offline
        S Offline
        SimonSchroeder
        wrote on last edited by
        #3

        @AnneRanch said in How to "break_up" single methoid / function...:

        or at minimum - some kind of status display

        For this variant (and if you don't use separate threads yet) you can use a QProgressDialog (mostly helpful if you know the number of tasks beforehand). If a single task takes too long, there are tricks using QApplication::processEvents(). However, this will slow down each single task and is not a recommended methods. The best solution (as already suggested by @SamiV123) is to use a separate thread for the tasks, so that the GUI can stay responsive.

        A 1 Reply Last reply
        1
        • S SimonSchroeder

          @AnneRanch said in How to "break_up" single methoid / function...:

          or at minimum - some kind of status display

          For this variant (and if you don't use separate threads yet) you can use a QProgressDialog (mostly helpful if you know the number of tasks beforehand). If a single task takes too long, there are tricks using QApplication::processEvents(). However, this will slow down each single task and is not a recommended methods. The best solution (as already suggested by @SamiV123) is to use a separate thread for the tasks, so that the GUI can stay responsive.

          A Offline
          A Offline
          Anonymous_Banned275
          wrote on last edited by
          #4

          @SimonSchroeder OK, I am game to try threads. My tasks are both "system calls" and QProcess - any "gotcha" there ?

          S 1 Reply Last reply
          0
          • A Anonymous_Banned275

            @SimonSchroeder OK, I am game to try threads. My tasks are both "system calls" and QProcess - any "gotcha" there ?

            S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #5

            @AnneRanch said in How to "break_up" single methoid / function...:

            My tasks are both "system calls" and QProcess - any "gotcha" there ?

            Nothing comes to mind right away. Those should have no (extra) problems when used inside threads. BTW, the easiest way to use threading in Qt is by using QtConcurrent::run(...).

            J.HilkJ 1 Reply Last reply
            0
            • S SimonSchroeder

              @AnneRanch said in How to "break_up" single methoid / function...:

              My tasks are both "system calls" and QProcess - any "gotcha" there ?

              Nothing comes to mind right away. Those should have no (extra) problems when used inside threads. BTW, the easiest way to use threading in Qt is by using QtConcurrent::run(...).

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @SimonSchroeder said in How to "break_up" single methoid / function...:

              BTW, the easiest way to use threading in Qt is by using QtConcurrent::run(...)

              Thats a debatable opinion.


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              A 1 Reply Last reply
              1
              • J.HilkJ J.Hilk

                @SimonSchroeder said in How to "break_up" single methoid / function...:

                BTW, the easiest way to use threading in Qt is by using QtConcurrent::run(...)

                Thats a debatable opinion.

                A Offline
                A Offline
                Anonymous_Banned275
                wrote on last edited by
                #7

                @J-Hilk OK, whatever I pick I still have to "split" the current function I have now, correct ?
                PS.
                (Almost) every time I ask similar question I get "it will slow down...". To me it is immaterial since my "process" is HARDWARE dependent, so some minor "software delay" does not matter... I just need each task to post "progress state"...

                PPS
                Just to be on safe side, and not to break the code too much , I will "split" the last task first....

                mzimmersM 1 Reply Last reply
                0
                • A Anonymous_Banned275

                  @J-Hilk OK, whatever I pick I still have to "split" the current function I have now, correct ?
                  PS.
                  (Almost) every time I ask similar question I get "it will slow down...". To me it is immaterial since my "process" is HARDWARE dependent, so some minor "software delay" does not matter... I just need each task to post "progress state"...

                  PPS
                  Just to be on safe side, and not to break the code too much , I will "split" the last task first....

                  mzimmersM Offline
                  mzimmersM Offline
                  mzimmers
                  wrote on last edited by
                  #8

                  @AnneRanch said in How to "break_up" single methoid / function...:

                  whatever I pick I still have to "split" the current function I have now, correct ?

                  Seems to me that it depends on what you mean by "split" - if you use the above suggestions, you can retain a single worker function that does all the HW stuff you mention. As that function makes progress, it can send signals to the main thread to update the UI. So, if I understand the use case, all the "work" can be performed within a single function.

                  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