Results 1 to 7 of 7

Thread: want to get thread to stop when application exits

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4

    Default Re: want to get thread to stop when application exits

    In response to Chrisw67, the thread checks this flag right after the gui thread releases a lock, so the destructor actually looks like this:

    MainWindow::~MainWindow()
    {

    fprintf(dfp,"\n\n=================EXITING APPLICATION====================\n\n");
    app_trying_to_exit = true;
    sysmutex.unlock();
    delete ui;
    }

    Note I don't see the output from fprintf in my log file.


    In response to Wysota, I will look into non thread pool threads. Note the thread waits on a lock for 99% of the time, so maybe starving the app this isn't a problem.

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

    Default Re: want to get thread to stop when application exits

    It is, because the thread is created and reserved. The fact that it sleeps is meaningless. If you try to start another thread from the pool that has only one thread, the thread will not start until the first one exits (which happens when the application is destroyed) so in practice the second thread will not run at all. You would have to release the thread before going to sleep on the mutex and reserve it back again when you are woken up. However it simply makes no sense to complicate things that much in this particular case since it's much easier to use QThread.
    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.


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

    dan146 (2nd May 2012)

  4. #3
    Join Date
    Feb 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4

    Default Re: want to get thread to stop when application exits

    Sorry for the slow reply, I'm juggling 3 projects. Yes I used QThread and it works great now! The flag is now seen by the thread and it exits properly.
    Thanks!

Similar Threads

  1. howto Processing GUI events until a thread exits
    By doggrant in forum Qt Programming
    Replies: 0
    Last Post: 5th October 2009, 15:50
  2. [QThread] Function calling after thread.stop()
    By Macok in forum Qt Programming
    Replies: 4
    Last Post: 7th February 2009, 13:33
  3. ¿How to stop thread that is capturing from a webcam?
    By JoseTlaseca in forum Qt Programming
    Replies: 8
    Last Post: 28th August 2008, 04:45
  4. Stop the thread during recursivly loading directory
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2007, 19:02
  5. Stop the thread
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2007, 10:29

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.