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 do you use threads in a very heavy loop process in one class and without using additional class objects?
Forum Updated to NodeBB v4.3 + New Features

how do you use threads in a very heavy loop process in one class and without using additional class objects?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 336 Views 1 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.
  • B Offline
    B Offline
    Blackzero
    wrote on last edited by
    #1

    I created a process in the loop and required me to use progresbar, but the problem is that progresbar and the window lag, people suggest using a thread object class with emit method but the problem is that my code is already quite a lot and it is not possible to move and rearrange everything it will make me crazy, is there any other way for this problem without having to create a new class to use threads?

    Christian EhrlicherC 1 Reply Last reply
    0
    • B Blackzero

      I created a process in the loop and required me to use progresbar, but the problem is that progresbar and the window lag, people suggest using a thread object class with emit method but the problem is that my code is already quite a lot and it is not possible to move and rearrange everything it will make me crazy, is there any other way for this problem without having to create a new class to use threads?

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Blackzero said in how do you use threads in a very heavy loop process in one class and without using additional class objects?:

      is there any other way for this problem without having to create a new class to use threads?

      No.
      Properly design your app 🙂

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      B 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @Blackzero said in how do you use threads in a very heavy loop process in one class and without using additional class objects?:

        is there any other way for this problem without having to create a new class to use threads?

        No.
        Properly design your app 🙂

        B Offline
        B Offline
        Blackzero
        wrote on last edited by
        #3

        @Christian-Ehrlicher Is that the only way ?

        M 1 Reply Last reply
        0
        • B Blackzero

          @Christian-Ehrlicher Is that the only way ?

          M Offline
          M Offline
          mpergand
          wrote on last edited by mpergand
          #4

          @Blackzero
          Is your process stepable, I mean it can process by step ?

          B 1 Reply Last reply
          0
          • M mpergand

            @Blackzero
            Is your process stepable, I mean it can process by step ?

            B Offline
            B Offline
            Blackzero
            wrote on last edited by
            #5

            @mpergand yes gradually, in the loop process or "for (;;)" calls one by one function or method after the first method is finished will run the second method in each method there is a loop back yes that is to display to progressesbar, but especially the loop that displays the progressesbar value so as not to lag I have tried using the

            std::thread thread(&MainWindow::WorkerThread, this);
            thread.detach();
            

            but an error appears
            QObject::startTimer: Timers cannot be started from another thread

            M 1 Reply Last reply
            0
            • B Blackzero

              @mpergand yes gradually, in the loop process or "for (;;)" calls one by one function or method after the first method is finished will run the second method in each method there is a loop back yes that is to display to progressesbar, but especially the loop that displays the progressesbar value so as not to lag I have tried using the

              std::thread thread(&MainWindow::WorkerThread, this);
              thread.detach();
              

              but an error appears
              QObject::startTimer: Timers cannot be started from another thread

              M Offline
              M Offline
              mpergand
              wrote on last edited by mpergand
              #6

              @Blackzero said in how do you use threads in a very heavy loop process in one class and without using additional class objects?:

              yes gradually,

              So you need to have a instance var to memorize the current step.
              For each step you need to call the event loop,
              the idea in pseudo code

              void processNextStep() // must be defined as a slot
              {
              process current step
              if last step return
              current step++
              update progressbar
              call slot processNextStep // see below
              }

              You have two ways to call the slot method
              1- QMetaObject::invokeMethod in mode Qt::QueuedConnection
              2- QTimer::singleShot((0)

              See the docs for more infos.

              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