Results 1 to 4 of 4

Thread: windows still exists after closeAllSubWindows()

  1. #1
    Join Date
    Jun 2015
    Location
    California, USA
    Posts
    61
    Thanks
    43
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11

    Default windows still exists after closeAllSubWindows()

    Any idea why a window is found by mdiArea->currentSubWindow()
    directly after mdiArea->closeAllSubWindows()?
    mdiArea is a class member for a QMainWindow subclass.

    The windows appear to have been closed after the function (QMainWindow::closeEvent) returns.
    And the next time the function runs it will find the currentSubWindow to be null.

    Qt Code:
    1. mdiArea->closeAllSubWindows();
    2. qDebug() << mdiArea->subWindowList().length();
    To copy to clipboard, switch view to plain text mode 

    If I have 2 sub-windows open,
    the debug ouput is 2.

    Qt 5.5 / win 7
    Last edited by ravas; 27th October 2015 at 08:55.

  2. #2
    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: windows still exists after closeAllSubWindows()

    My guess: there is no chance for the event loop to run between those two calls and the first call only calls close() on the subwindows.
    Boy, wouldn't it be nice we could look at the code of that function?

    Cheers,
    _

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

    ravas (27th October 2015)

  4. #3
    Join Date
    Jun 2015
    Location
    California, USA
    Posts
    61
    Thanks
    43
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11

    Default Re: windows still exists after closeAllSubWindows()

    Qt Code:
    1. mdiArea->closeAllSubWindows();
    2. if (mdiArea->currentSubWindow()) {
    3. ce->ignore();
    4. } else {
    5. ce->accept();
    6. }
    To copy to clipboard, switch view to plain text mode 

    It worked before (close all subwindows then accept the close event),
    but I recently subclassed QMdiSubWindow,
    where before they were created automatically by mdiArea->addSubWindow(widget).
    The only difference I can think of is that the subclass sets setAttribute(Qt::WA_DeleteOnClose);
    however, removing that makes it so the subwindows aren't even closed.


    Added after 21 minutes:


    Another difference is that the QMdiSubWindow has a reimplemented closeEvent function;
    although, that seems to run OK.
    Last edited by ravas; 27th October 2015 at 19:13.

  5. #4
    Join Date
    Jun 2015
    Location
    California, USA
    Posts
    61
    Thanks
    43
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11

    Default Re: windows still exists after closeAllSubWindows()

    I'm thinking that calling closeAllSubWindows is not needed.
    The windows will be dealt with when the main window is deleted.

    Thanks for the idea about the event loop.
    Last edited by ravas; 28th October 2015 at 01:36.

Similar Threads

  1. detect if a URL exists or not
    By timmu in forum Qt Programming
    Replies: 5
    Last Post: 27th January 2013, 13:16
  2. File exists on server
    By Chops211 in forum Qt Programming
    Replies: 5
    Last Post: 6th August 2011, 20:22
  3. Replies: 2
    Last Post: 21st February 2011, 14:52
  4. Replies: 1
    Last Post: 1st September 2010, 10:23
  5. Does anyone know if anything like this exists for Qt
    By Jachyra in forum Qt Programming
    Replies: 3
    Last Post: 8th February 2007, 22:06

Tags for this Thread

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.