Results 1 to 9 of 9

Thread: QDialog closing its parent on exit..

  1. #1
    Join Date
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QDialog closing its parent on exit..

    In order to abstract a problem to a global level (I know..) I've built a static "create_keypad" function that provides most of the default initialization and such.

    In the current implementation I pass in a parent widget, though I've done it both ways. Either way I do it (manual memory management or garbage collection) the keypad kills my main window on exit. Because it didn't before I abstracted I have to assume it has something to do with a modal dialog box becoming some sort of "primary window" in the main event loop despite giving it my window as a parent (or not.)

    Possibly the accept() or reject() signals going to the main-event loop (I'd assume..?) implies that the loop should end?

    If someone could shed light on this it'd be quite helpful; as I'd prefer a generic static/global function for this task. (After all, someone else may wish to use it in the future outside of this class.) I may note that the initialization could (mostly) be abstracted to another subclass of my subclass (of QDialog), but that seems unnecessary (and I'm unsure if it's better design at that point or not.)


    Snippet for completion:
    Qt Code:
    1. class Thang : public QDialog {/*...*/};
    2.  
    3. static Thang* create_thang(QWidget* parent) //!!remember, with or without this parent my program quits
    4. {
    5. Thang* thang = new Thang(parent);
    6.  
    7. //..
    8. //bunch of init code..
    9.  
    10. return thang;
    11. }
    12.  
    13. static void use_Thang (Thang* thang)
    14. {
    15. thang->exec();
    16.  
    17. //..
    18. //special value handling/signal emission..
    19. }
    To copy to clipboard, switch view to plain text mode 


    Whether or not I'm critiqued on the obvious strangeness of the design, (it just feels* right to me,) I'd like to know why the loop is getting killed (or I if not, why my other windows are getting killed and thus the loop being killed.)

    *[for the sake of keeping changes for the many keypads entry/exit point the same and thus the code to modify these the same/in-one-place]


    Thanks for any info!

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDialog closing its parent on exit..

    show a simple compilable example... read my sig (again )
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QDialog closing its parent on exit..

    Hm.. I attempted to replicate the problem in a few ways on a smaller project.. but it worked as normal :s. I can't really put up the entirety of the program ( a mix of environment, external dependencies, and the thing is quite large; even if just the GUI code.)

    I'll keep tinkering and report my findings.. if I figure it out before defaulting to just using member functions. I was hoping there was some (possibly obvious) oversight in my misunderstanding the event loop and static/global objects (or something along those lines.)

  4. #4
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QDialog closing its parent on exit..

    Maybe Your other (main) widget is hidden?
    If Yes then closing last visible window will close app.

    Try: thang->setAttribute(Qt::WA_QuitOnClose, false);
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  5. The following user says thank you to Talei for this useful post:

    tescrin (18th December 2012)

  6. #5
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDialog closing its parent on exit..

    Quote Originally Posted by tescrin View Post
    Hm.. I attempted to replicate the problem in a few ways on a smaller project.. but it worked as normal :s. I can't really put up the entirety of the program ( a mix of environment, external dependencies, and the thing is quite large; even if just the GUI code.)

    I'll keep tinkering and report my findings.. if I figure it out before defaulting to just using member functions. I was hoping there was some (possibly obvious) oversight in my misunderstanding the event loop and static/global objects (or something along those lines.)
    This is exactly the reason for making a small compilable example. Instead of asking the forum to chase ghosts, you check the problem is actually what you try to describe with 'snippets' that obviously don't contain the problem.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  7. The following user says thank you to amleto for this useful post:

    tescrin (18th December 2012)

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDialog closing its parent on exit..

    Does the program quit or does it crash?
    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.


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

    tescrin (18th December 2012)

  10. #7
    Join Date
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QDialog closing its parent on exit..

    @amleto
    That's what I tried to do lol, but it worked as normal. I did several tests to try and manipulate the example to be as close as possible (menu button, using an action to trigger, global/static functions, etc..) I just couldn't get it to fail. If I get 3 or 4 classes deep trying to replicate a problem; I've done what I can in a reasonable amount of time without just taking the shortcut of doing what I know works (but is more poor from a repeated code point of view.) But it's no matter because:..

    @Talei
    That fixed it! I didn't ever call hide on my main window.. but maybe something about this being a modal dialog (thusly pushing the other back) counts as hidden.. or something. Either way, thank you very much for the suggestion! You're obviously psychic lol. I'm guessing I've done something slightly odd with the Mainwindow's hierarchy or something (I have a separate class that controls the window in order to manage an overlay.)

    @Wysota
    Well I guess it's more obvious now, but it was just closing; which was part of my issue. A crash I have all sorts of tools to deal with . I had assumed crashing at first as I'm doing naughty things like passing member-function-pointers around; but alas, they all worked.


    Thank you all for the input!

  11. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDialog closing its parent on exit..

    Quote Originally Posted by tescrin View Post
    I didn't ever call hide on my main window.. but maybe something about this being a modal dialog (thusly pushing the other back) counts as hidden.. or something.
    No, it doesn't. If a window is hidden then something has called hide() or close() on it.
    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.


  12. #9
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDialog closing its parent on exit..

    Quote Originally Posted by wysota View Post
    No, it doesn't. If a window is hidden then something has called hide() or close() on it.
    or it was never shown...
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. QDialog not closing/going out of scope?
    By Shouri in forum Newbie
    Replies: 4
    Last Post: 17th February 2012, 18:11
  2. Replies: 5
    Last Post: 21st April 2010, 21:36
  3. How to exit in a QDialog constructor
    By ms77 in forum Newbie
    Replies: 4
    Last Post: 2nd December 2009, 14:46
  4. closing a Qdialog called from a Qdialog
    By OverTheOCean in forum Qt Programming
    Replies: 3
    Last Post: 28th September 2009, 08:02
  5. Closing a QDialog
    By eu.x in forum Newbie
    Replies: 2
    Last Post: 12th March 2007, 08:33

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.