Results 1 to 9 of 9

Thread: need advice on gui thread

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: which is the correct implementation for worker threas

    Quote Originally Posted by dpn View Post
    I have goggled for qt worker threads. I am new to Qt. I found three kinds of implementations.

    1. Inherit worker class from QThread and override Run()
    2. Create QThread object as member variable of worker class
    3. make it as a thread by using movetothread.
    You have two options here: 1 and 3. 2 alone does not make the worker code execute in the second thread.

    Quote Originally Posted by dpn View Post
    In which scenario, I have to use 1st approach. If possible, plz explain about other approaches.
    The 1st approach is useful if the parallized operation does not need an event loop, e.g. some form of blocking loop.
    The other approach is useful if you need an event loop.

    Cheers,
    _

  2. The following user says thank you to anda_skoa for this useful post:

    dpn (16th September 2013)

  3. #2
    Join Date
    Nov 2012
    Posts
    21
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: which is the correct implementation for worker threas

    Should application delete thread and worker objects?

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: which is the correct implementation for worker threas

    Quote Originally Posted by dpn View Post
    Should application delete thread and worker objects?
    The application should always clean up the mess it has done.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: which is the correct implementation for worker threas

    The real answer (to the original thread question), as most of the time is: "it depends".
    On many things and considerations.
    So a real "right way of doing it" is not something absolute.
    Usually however, if you design your code well and in OOP way, what ever it is you want your worker thread to do should be encapsulated in a way which is not dependent (but capable) of running in a thread.
    This usually will translate to NOT needing to subclass a QThread.
    This issue got to be somewhat of a religious issue over the past years.
    Different people just feel that one way is more right than the other.
    The test is in the real word: which implementation fits your design the best way on all fronts:
    readability, re-usability, maintenance (such the the open-close principal) etc.
    Here is a interesting post by an (ex?) troll, where he answers another blog post (be sure to read it, its linked in the blog text!).
    Once you have read it, make the best decision for your case.
    And don't let anyone else tell you if its wrong or right, unless they can prove their claim with valid points to your specific case.
    http://woboq.com/blog/qthread-you-we...-so-wrong.html
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 1
    Last Post: 25th October 2012, 15:10
  2. Replies: 1
    Last Post: 28th March 2012, 18:58
  3. Replies: 9
    Last Post: 28th November 2009, 20:31
  4. Thread design advice needed
    By jonks in forum Qt Programming
    Replies: 3
    Last Post: 22nd October 2009, 21:32
  5. Advice needed regarding GUI and external thread cooperation
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 17th June 2009, 00:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.