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. qthread with multiple tasks and void
Forum Updated to NodeBB v4.3 + New Features

qthread with multiple tasks and void

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 780 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.
  • faduF Offline
    faduF Offline
    fadu
    wrote on last edited by fadu
    #1

    hello
    first of all i'm new in qt
    i have a lot of void in my application
    and all have a long task
    my question is which is the best way to make qthread for all voids
    can i create a qthread and worker class and load a void to the worker
    or i must create qthread class to each one

    jsulmJ 1 Reply Last reply
    0
    • faduF fadu

      @jsulm i didn't get the right answer can i make a primary qthread or woker and load a function to the the thread then call the thread instead of functions

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @fadu said in qthread with multiple tasks and void:

      then call the thread instead of functions

      You don't call a thread you start it.
      You should describe better your use case to get better answer.
      Do you want to execute several functions in parallel at the same time? If so then you need more than one thread because one thread can only execute one function at given time.
      With QThread you can use signals and slots to communicate between threads and to trigger actions in threads.
      You should take a look at https://doc.qt.io/qt-5/thread-basics.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • faduF fadu

        hello
        first of all i'm new in qt
        i have a lot of void in my application
        and all have a long task
        my question is which is the best way to make qthread for all voids
        can i create a qthread and worker class and load a void to the worker
        or i must create qthread class to each one

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @fadu said in qthread with multiple tasks and void:

        i have a lot of void in my application

        What do you mean by "void"? Do you mean you have many functions?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • faduF Offline
          faduF Offline
          fadu
          wrote on last edited by
          #3

          @jsulm yes many function with a long tasks

          jsulmJ 1 Reply Last reply
          0
          • faduF fadu

            @jsulm yes many function with a long tasks

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @fadu Which technique to use depends on exact use case.
            The easiest way to run a function in background is to use https://doc.qt.io/qt-5/qtconcurrent.html#run

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • faduF Offline
              faduF Offline
              fadu
              wrote on last edited by
              #5

              @jsulm i didn't get the right answer can i make a primary qthread or woker and load a function to the the thread then call the thread instead of functions

              jsulmJ 1 Reply Last reply
              0
              • faduF fadu

                @jsulm i didn't get the right answer can i make a primary qthread or woker and load a function to the the thread then call the thread instead of functions

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @fadu said in qthread with multiple tasks and void:

                then call the thread instead of functions

                You don't call a thread you start it.
                You should describe better your use case to get better answer.
                Do you want to execute several functions in parallel at the same time? If so then you need more than one thread because one thread can only execute one function at given time.
                With QThread you can use signals and slots to communicate between threads and to trigger actions in threads.
                You should take a look at https://doc.qt.io/qt-5/thread-basics.html

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • faduF Offline
                  faduF Offline
                  fadu
                  wrote on last edited by
                  #7

                  @jsulm thanks a lot this what i searching about it
                  i just asking for the right way to make my codes better and stable

                  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