Results 1 to 8 of 8

Thread: Why should a removeSubWindow() raise exception?

  1. #1
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question Why should a removeSubWindow() raise exception?

    Hi all,
    my question tells for your very wide experience:
    what are all the motivations for which a QMdiArea::removeSubWindow(QWidget* widget) should fail, raising an exception (and, so, crashing the program)?

    Details:
    MDI application.
    QDialog as widget in a QMdiSubWindow.
    When closing it, following rows are executed:
    Qt Code:
    1. mdiArea->removeSubWindow(wArticle);
    2. delete pArticle;
    3. pArticle=NULL;
    4. wArticle=NULL;
    To copy to clipboard, switch view to plain text mode 
    where:
    mdiArea => QMdiArea*
    wArticle => QMdiSubWindow*
    pArticle => QDialog* (contained by wArticle)
    The first of the four instructions raises an exception and makes crash the program.
    So, what I'm asking is: what has wArticle to have of strange (since I checked it is not NULL) to make the method fail?
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Why should a removeSubWindow() raise exception?

    Either pointer could be a dangling pointer. You could have forgotten to initialize it or it could've been already deleted (and forgot to nullify).
    J-P Nurmi

  3. #3
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Why should a removeSubWindow() raise exception?

    Quote Originally Posted by jpn View Post
    Either pointer could be a dangling pointer. You could have forgotten to initialize it or it could've been already deleted (and forgot to nullify).
    Yes, I agree with you; maybe wArticle has been already deleted (probabily in a tricky way).

    I read docs: so have I to delete wArticle after removing it from MdiArea, since it is not removed by removeSubWindow()? Is it right?
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Why should a removeSubWindow() raise exception?

    Usually QMdiSubWindows have Qt::WA_DeleteOnClose set which means they'll get deleted upon close event.
    J-P Nurmi

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

    Raccoon29 (20th March 2008)

  6. #5
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Why should a removeSubWindow() raise exception?

    Quote Originally Posted by jpn View Post
    Usually QMdiSubWindows have Qt::WA_DeleteOnClose set which means they'll get deleted upon close event.
    Thank you, yes, now it is bright!

    Update from the solving:
    I tried to comment the row that raised the error (removeSubWindow()), and now everything works fine; I set the Qt::WA_DeleteOnClose so maybe when closing the window it got deleted, and when the method tried to remove it with the function, it found a deallocated memory: dump.
    But now I'm wondering about the usefulness of the method removeSubWindow()... removing it, I don't risk memory lacks or something? The problem doesn't exist if what I just said is right, and DeleteOnClose works for it...

    Anyway thank you very much,
    you guru members make this forum unbeatable!
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  7. #6
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Question Re: Why should a removeSubWindow() raise exception?

    I have another question that I think is related to this thread, so I didn't start a new one.

    A Qt::WA_DeleteOnClose for a MdiSubWindow, when the subwindow get closed with event->accept() (in closeEvent()), deletes the QMdiSubWindow, or the QWidget inside it, or both of them??
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why should a removeSubWindow() raise exception?

    Quote Originally Posted by Raccoon29 View Post
    A Qt::WA_DeleteOnClose for a MdiSubWindow, when the subwindow get closed with event->accept() (in closeEvent()), deletes the QMdiSubWindow, or the QWidget inside it, or both of them??
    If that attribute was set for MDI subwindow, it will delete the subwindow and all child widgets.

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

    Raccoon29 (21st March 2008)

  10. #8
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Why should a removeSubWindow() raise exception?

    Quote Originally Posted by jacek View Post
    If that attribute was set for MDI subwindow, it will delete the subwindow and all child widgets.
    Ok. Thank you jacek.
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

Similar Threads

  1. Exceptions and qApp->processEvents()
    By mcostalba in forum Qt Programming
    Replies: 3
    Last Post: 8th January 2006, 17:06

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.