Results 1 to 2 of 2

Thread: Application doesn't reaaly close

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2013
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Application doesn't reaaly close

    Hello,

    I noticed that if I close my application during a long task like "reading a big file, the GUI window close well but application only stop at the end of the reading. So I did some test, and if I do this:


    Qt Code:
    1. void MYGUI::on_pushButton_ReadFile_clicked()
    2. {
    3. int i=0;
    4. while(1)
    5. {
    6.  
    7. i++;
    8. qDebug() << "TEST" << i;
    9. QCoreApplication::processEvents();
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    when I close the application by clicking on the cross on the upper right of my application window (on Windows 10), it close well the window, but the application still run in the task manager and I have to manually kill it in the task manager or in the cmd prompt with taskkill /IM myApp.exe /F.

    Is someone has a clue to be sure to close the entire application when needed even if processing a "big task" please?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Application doesn't reaaly close

    Clicking the "Close" (X) button on a top-level window's title bar closes the window, not the app unless QGuiApplication::quitOnLastWindowClosed() is true (the default). If you have background processing that does not allow control to return to the main Qt event loop - like your example code above - the close event will never be seen by the main event loop. Your infinite loop has in effect set up an internal event loop (just like a modal dialog) which handles its own events (but not events posted to the main event loop).

    Your code above is a slot. The rule for Qt is that control does not return to the main event loop until a slot has finished executing. Since your slot never exits, the app can never exit.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Qt application doesn't close properly during QEventloop
    By jigglyslime in forum Qt Programming
    Replies: 9
    Last Post: 6th November 2013, 09:03
  2. QNetworkReply doesn't abort/close - PyQT
    By dan252 in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2013, 00:41
  3. QT application not close after close the mainwindow
    By artome in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2011, 22:23
  4. Replies: 2
    Last Post: 17th December 2010, 19:01
  5. Replies: 3
    Last Post: 23rd July 2006, 18:02

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.