Results 1 to 3 of 3

Thread: I'm failing with Threading

  1. #1
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default I'm failing with Threading

    I've got a widget that I want to have operate inside its own thread, SWidget. I've got another class called SWidgetThread that inherits QThread. It declares a new SWidget and then fires off exec() inside its run() function so that that thread has its own event loop.

    the problem that I'm running into is that I want a TabWidget to have each tab (made up of a SWidget) run in a seperate thread. So I was trying to have my TabWidget create a new SWidgetThread object, and then I ask my SWidgetThread object for a pointer to its SWidget and that is the widget that I give to the TabWidget as its page. But later when I go to get rid of the tab, I get a pointer to the page, but that page's->thread object is the same as the TabWidget's->thread. So when I call quit() on my page, it kills the main thread.

    Help?
    Paul

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: I'm failing with Threading

    Only objects created in the run method live in the worker thread.
    The widget lives in the GUI thread(as it should be!!!) because you create it in the QThread constructor.

    Anyhow, this design doesn't sound good at all. First of all widgets MUST not be modified directly by other threads than the GUI thread(I am not sure if you respect that), instead you should use signals and slots/events.

    Second, this widget-thread association doesn't have to be like that. You could do it in countless other ways, such as maps, a widget/thread pair class, etc..

  3. The following user says thank you to marcel for this useful post:

    thomaspu (11th January 2008)

  4. #3
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: I'm failing with Threading

    Ok, that clears things up. I think I'm doing things really wrong then and need to rethink my design ;p

    Paul

Similar Threads

  1. Correct Threading Technique
    By themusicalguy in forum Qt Programming
    Replies: 10
    Last Post: 2nd November 2007, 14:28
  2. Threading Issue
    By noufalk in forum Qt Programming
    Replies: 4
    Last Post: 4th August 2007, 13:45
  3. Multi threading ...
    By kiranraj in forum Qt Programming
    Replies: 2
    Last Post: 18th June 2007, 16:51
  4. Threading and plotting graph in same program.
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 9th May 2007, 20:42
  5. Newbie threading question
    By deepayan in forum Qt Programming
    Replies: 17
    Last Post: 16th April 2007, 00:25

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.