Results 1 to 9 of 9

Thread: closing parent widget during QMenu::exec()

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2014
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default closing parent widget during QMenu::exec()

    I have an open QDialog and create a popup menu and show it with QMenu::exec().
    Qt Code:
    1. QMenu *menu=new QMenu(mydialog);
    2. ...
    3. QAction *ret=menu->exec();
    4. delete menu;
    To copy to clipboard, switch view to plain text mode 
    On a Mac it is possible to close the dialog while the menu is open. The menu is closed and destroyed automatically since it is a child of the dialog. However, QMenu::exec() returns after dialog and menu have been destroyed, and the line "delete menu" in the above code creates a crash. Unter Windows this situation never appears because clicking on the dialog's close button closes the menu first and only a second click closes the dialog.

    1) Can I just omit the line "delete menu"? Would it create a memory leak if the menu is closed regularly?
    2) Is there some way to determine if a QObject still exists or is already destroyed?
    Last edited by hartmut; 30th January 2016 at 22:31. Reason: typo in title

Similar Threads

  1. Replies: 1
    Last Post: 11th March 2011, 19:34
  2. QMenu exec under MacOSX
    By yxtx1984 in forum Qt Programming
    Replies: 0
    Last Post: 16th December 2010, 05:13
  3. How to make QMenu.exec() return a QWidgetAction
    By gregsan in forum Qt Programming
    Replies: 5
    Last Post: 15th April 2010, 00:04
  4. Replies: 0
    Last Post: 16th March 2010, 12:24
  5. Replies: 7
    Last Post: 14th January 2010, 08:47

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.