Results 1 to 4 of 4

Thread: Qt and number crunching

  1. #1
    Join Date
    Mar 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Qt and number crunching

    Hi there,

    this is my first post to this forum, so important things first: Hello everyone! :-)
    I'm using Qt for quite some time now, but of course there are always things to learn...
    And I would like to start with this:

    I'm doing some heavy duty number crunching, which can keep my poor computer busy for several hours quite easily. In between I would like to have a Qt window updated with some status messages and plots.
    What I'm doing right now is put all the number crunching in a QThread and create the dialog in its constructor, so that it runs in the GUI thread. But to be honest I really think, this is the wrong way, since the number crunching should be the main thread and GUI in some low priority thread. But if I put all the GUI stuff into a separate thread, I run into problems, since I need to do all GUI calls from a single thread.
    How do you handle this? Any help would be appreciated. Thanks.

    Cheers,
    Tim

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt and number crunching

    I always have the GUI thread as the main thread of execution, and have all the number crunching in another thread. The threads then send back status information to the main thread using signals and slots. The GUI only ever updates when needed, so there's no need for it to be low priority, as it uses far less than 1% of the CPU time anyway as it spends most of the time sleeping.

    In your case, I wouldn't create a dialog in the number crunching threads constructor - I would create a thread that does nothing but number crunching, and simply broadcasts status signals which the main thread would pickup and do things with.

  3. #3
    Join Date
    Mar 2010
    Posts
    21
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt and number crunching

    Thanks. I've just implemented this. The threads are now communicating only using signals/slots, which are completely thread-safe, aren"t they? But anyway, seems to work nicely, thanks again.

  4. #4
    Join Date
    Apr 2009
    Posts
    36
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt and number crunching

    Quote Originally Posted by The_Fallen View Post
    Thanks. I've just implemented this. The threads are now communicating only using signals/slots, which are completely thread-safe, aren"t they? But anyway, seems to work nicely, thanks again.
    Yes, they are thread safe.

Similar Threads

  1. Complex number
    By nbo10 in forum Qt Programming
    Replies: 1
    Last Post: 4th April 2009, 06:44
  2. Different number of columns in each row
    By 1111 in forum Qt Programming
    Replies: 6
    Last Post: 9th March 2009, 08:44
  3. Number of folder
    By Benjamin in forum Qt Programming
    Replies: 1
    Last Post: 3rd December 2008, 10:33
  4. Number formats 00.00
    By maverick_pol in forum Qt Programming
    Replies: 21
    Last Post: 15th October 2007, 17:32
  5. xml - get number of columns
    By wind in forum Newbie
    Replies: 3
    Last Post: 1st November 2006, 10:38

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.