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. run vs movetothread ? (thread)
Forum Updated to NodeBB v4.3 + New Features

run vs movetothread ? (thread)

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 5 Posters 4.8k 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.
  • M Offline
    M Offline
    mduzoylum
    wrote on last edited by
    #1

    hi everyone,

    what is the difference between run() vs movetothread() functions to use thread?

    JonBJ KroMignonK 2 Replies Last reply
    0
    • M mduzoylum

      thats right @JonB .
      Is there a difference in performance or anything else?

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

      @mduzoylum
      let's put it this way,
      you need significantly more knowledge to correctly subclass QThread and (correctly)override run, than to simply move one object instance to an other thread


      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.

      1 Reply Last reply
      2
      • M mduzoylum

        hi everyone,

        what is the difference between run() vs movetothread() functions to use thread?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @mduzoylum
        QThread::run() runs a thread, QObject::moveToThread() moves an object to a thread (slots run in that thread).

        1 Reply Last reply
        3
        • M Offline
          M Offline
          mduzoylum
          wrote on last edited by
          #3

          thats right @JonB .
          Is there a difference in performance or anything else?

          JonBJ J.HilkJ 2 Replies Last reply
          0
          • M mduzoylum

            thats right @JonB .
            Is there a difference in performance or anything else?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

            @mduzoylum
            I don't know what you mean. They perform two quite distinct operations. You can't "compare their performance".

            1 Reply Last reply
            1
            • M mduzoylum

              thats right @JonB .
              Is there a difference in performance or anything else?

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

              @mduzoylum
              let's put it this way,
              you need significantly more knowledge to correctly subclass QThread and (correctly)override run, than to simply move one object instance to an other thread


              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.

              1 Reply Last reply
              2
              • M mduzoylum

                hi everyone,

                what is the difference between run() vs movetothread() functions to use thread?

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on last edited by
                #6

                @mduzoylum said in run vs movetothread ? (thread):

                what is the difference between run() vs movetothread() functions to use thread?

                Hello, your question is very strange and it seems to me that you don't understand what QThread is...
                Have you take a look at the QThread documentation?

                Why do you want to use threads?
                Do you aware about all Qt possibilities about multi-threading?
                Please read first this https://hub.packtpub.com/multithreading-qt/ to get a little in touch about what multi-thread is.

                Read documentation before trying to do multithread, or you will be very quickly frustrated.

                my 2 cts.

                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                M 1 Reply Last reply
                1
                • JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #7

                  There is also https://doc.qt.io/qt-5/threads-technologies.html

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  2
                  • KroMignonK KroMignon

                    @mduzoylum said in run vs movetothread ? (thread):

                    what is the difference between run() vs movetothread() functions to use thread?

                    Hello, your question is very strange and it seems to me that you don't understand what QThread is...
                    Have you take a look at the QThread documentation?

                    Why do you want to use threads?
                    Do you aware about all Qt possibilities about multi-threading?
                    Please read first this https://hub.packtpub.com/multithreading-qt/ to get a little in touch about what multi-thread is.

                    Read documentation before trying to do multithread, or you will be very quickly frustrated.

                    my 2 cts.

                    M Offline
                    M Offline
                    mduzoylum
                    wrote on last edited by
                    #8

                    @KroMignon

                    Is this to offend your answer ?
                    movetothread using for multithread, I know that.

                    I'm using thread in jobs that need to run continuously in the background(Is the answer enough?)
                    Yes I'm in the beginning but your answer is irrelevant.I recommend you to speak more constructively

                    KroMignonK 1 Reply Last reply
                    0
                    • M mduzoylum

                      @KroMignon

                      Is this to offend your answer ?
                      movetothread using for multithread, I know that.

                      I'm using thread in jobs that need to run continuously in the background(Is the answer enough?)
                      Yes I'm in the beginning but your answer is irrelevant.I recommend you to speak more constructively

                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on last edited by KroMignon
                      #9

                      @mduzoylum said in run vs movetothread ? (thread):

                      in jobs that need to run continuously in the background(Is the answer enough?)

                      I apologies if my answer is hurting you, this was not my intention.English is not my first language (I am french), so my answer is perhaps rudder as that I want to say :(

                      If you want to to work in background and continuously then create a worker class and assign it to a thread is, in my eyes, the right way as described in the link I give you in my previous message or those:

                      • http://blog.debao.me/2013/08/how-to-use-qthread-in-the-right-way-part-1/
                      • https://www.toptal.com/qt/qt-multithreading-c-plus-plus

                      If you just want to do a specific job in background and be informed when it is done, QtConcurrent::run() is what you need. This avoids you the create/destroy thread, you can simply call you function with specific parameters like this:

                      auto resultFuture = QtConcurrent::run(worker, &WorkerKlass::calculate, listOfItems);
                      

                      Then you can use QFutureWatcher to be aware when calculate is finished and get the return value:

                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                      1 Reply Last reply
                      6

                      • Login

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