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. QtThread
Qt 6.11 is out! See what's new in the release blog

QtThread

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 2.5k 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.
  • G Offline
    G Offline
    GrahamL
    wrote on last edited by
    #1

    Hi
    I have been reading about QtThread and there seems to be a lot of discussion about how to correctly use this class. i.e. should developers derive from QtThread or provide an QObject and move this object to a thread.
    The examples provided with Qt5 derive from QtThread whereas there is a lot of chatter on the web saying this is not the correct way.

    Can anyone provide some definitive answers on how developers are to use QtThread?

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The latest documentation of "QThread":http://qt-project.org/doc/qt-5/qthread.html shows both methods and in which circumstances they can/should be used. Is this what you were looking for ?

      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
      • G Offline
        G Offline
        GrahamL
        wrote on last edited by
        #3

        Thanks - I'll read this

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GrahamL
          wrote on last edited by
          #4

          Hi
          I need to implement a producer/consumer pattern
          As you know Qt provides 2 examples (mutexes and semaphores) and both derive from QtThread.
          I guess my question now becomes
          'to implement a producer/consumer pattern must I derive from QtThread?'

          Any thoughts?

          Thanks

          1 Reply Last reply
          0
          • JeroentjehomeJ Offline
            JeroentjehomeJ Offline
            Jeroentjehome
            wrote on last edited by
            #5

            Hi,
            It all depends on the implementation use of your multi threaded design!
            First read this:
            "Thread basics":http://qt-project.org/doc/qt-4.8/thread-basics.html
            It goes into QThread and QtConcurrent use and implementation. QThread is very low level and IYAM QtConcurrent is easier to implement.

            Greetz, Jeroen

            1 Reply Last reply
            0
            • G Offline
              G Offline
              GrahamL
              wrote on last edited by
              #6

              Hi
              Thats a great resource

              Thanks

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

                Hi,

                [quote author="Jeroentje@home" date="1389610503"]Hi,
                It all depends on the implementation use of your multi threaded design![/quote]
                Agreed!

                A few years ago, subclassing QThread was declared "wrong" because lots of people did it wrong.

                However, there are still valid cases where subclassing QThread is "better" than using moveToThread().

                For a comparison of different ways to use threads, see http://qt-project.org/doc/qt-5/threads-technologies.html

                [quote]First read this:
                "Thread basics":http://qt-project.org/doc/qt-4.8/thread-basics.html
                It goes into QThread and QtConcurrent use and implementation. QThread is very low level and IYAM QtConcurrent is easier to implement.
                [/quote]Unfortunately, that link is outdated and incomplete. Importantly, do NOT follow Example 3 -- it is an example of the definitely-bad way of using QThread!

                The updated, cleaned-up version is at http://qt-project.org/doc/qt-5/thread-basics.html . Follow the links inside it too -- they take you to other helpful pages on the topic of multithreading.

                [quote author="GrahamL" date="1389606322"]I need to implement a producer/consumer pattern
                As you know Qt provides 2 examples (mutexes and semaphores) and both derive from QtThread.
                I guess my question now becomes
                'to implement a producer/consumer pattern must I derive from QtThread?'[/quote]Did you meant wait conditions and semaphores? There are the 2 examples of the producer/consumer pattern that I know of:

                • http://qt-project.org/doc/qt-5/qtcore-waitconditions-example.html
                • http://qt-project.org/doc/qt-5/qtcore-semaphores-example.html

                These examples subclass QThread, and that's fine.

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

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  GrahamL
                  wrote on last edited by
                  #8

                  Ok
                  I am starting to understand
                  Thanks everyone

                  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