Results 1 to 20 of 46

Thread: What happens after closing and before destruction?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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

    Exclamation What happens after closing and before destruction?

    Hi all,

    I have two related questions to ask:
    1) Is it admitted to set the flag Qt::WA_DeleteOnClose for a QWidget, beyond that for the MDI subwindow that contains it?

    If the answer to the 1 is "Yes", the second question:
    2) What does a QWidget do right after accepting the closeEvent and before its desctruction?
    Because right now this function:
    Qt Code:
    1. void frmarticle::closeEvent(QCloseEvent *event)
    2. {
    3. if(!maybeSave()) // check for modifies apported
    4. {
    5. event->ignore(); //modifies apported stop the closement
    6. return;
    7. }
    8.  
    9. viewport->close(Article); //nullifies pointers
    10. event->accept(); //accepts close event, it is supposed to destroy this widget now, is it?
    11. }
    12. // now quits the closeEvent and the program raise exception, before calling the destructor
    To copy to clipboard, switch view to plain text mode 
    So, if I would know what it does after close event and before destructor, I could debug it; if you have any other suggestion don't be shy, I accept everything.
    --
    raccoon29

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

  2. #2
    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

    Unhappy Re: What happens after closing and before destruction?

    No one know where control goes after closing a Widget in a MDI system??
    --
    raccoon29

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

  3. #3
    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: What happens after closing and before destruction?

    You can use WA_DeleteOnClose for any widget you want. After an event is accepted, the control is returned to the event loop and the widget is most probably scheduled for deletion using deleteLater() (I'm not sure of that, but that's a quite safe thing to assume) and is deleted when the event queue reaches the delayed destruction event.

    I'd suggest using a debugger to see what and why crashes. Most probably you either have a null or invalid pointer or you are trying to delete an object inside a slot connected to a signal originating from the object itself.

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

    Raccoon29 (18th April 2008)

  5. #4
    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: What happens after closing and before destruction?

    Thank you, you have just made me find the courage to install the debug environment

    Once I have debugged it, I'll post here more informations.
    Thank you for the suggestion.
    --
    raccoon29

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

  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: What happens after closing and before destruction?

    Ok, debug installed and working, from its scan resulted the following (now we'll see how much deep is your Qt knowledge ):

    The application after closeEvent and before destruction stopped the run with the message:
    ASSERT failure in QList<T>::at: "index out of range", file ../../include/QtCore/../../src/corelib/tools/qlist.h, line 391

    What is the verdict?
    Last edited by Raccoon29; 18th April 2008 at 15:15. Reason: wrong instruction raising exception notified. Always changes.
    --
    raccoon29

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

  7. #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: What happens after closing and before destruction?

    "after closeEvent" meaning "after closeEvent returns" or "after closeEvent is called"? It'd say your viewport->close(Article) tries to reference some item in some list and fails because the list is smaller than it expects.

  8. #7
    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: What happens after closing and before destruction?

    "after closeEvent" meaning "after closeEvent returns" or "after closeEvent is called"?
    meaning "after closeEvent accepts the event and return", and I remember that the widget closed is a MdiSubWindow with WA_DeleteOnClose that contains frmarticle (inherited from QWidget)

    It'd say your viewport->close(Article) tries to reference some item in some list and fails because the list is smaller than it expects.
    Yes, I thought it too, but viewport->close(Article); is called to do just this:

    Qt Code:
    1. void CViewports::close(EViewport win)
    2. {
    3. switch(win)
    4. {
    5. // Article
    6. case 1:
    7. {
    8. if(pArticle) //pointer to frmarticle, not null for sure
    9. {
    10. pArticle=NULL;
    11. wArticle=NULL;
    12. }
    13.  
    14. break;
    15. }
    16. [...]
    17. }
    To copy to clipboard, switch view to plain text mode 
    Maybe, since the problem seems to be some list, could be the QTableWidget present in frmarticle be involved in the problem, or I'm totally off-road?
    --
    raccoon29

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

  9. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What happens after closing and before destruction?

    The application after closeEvent and before destruction stopped the run with the message:
    ASSERT failure in QList<T>::at: "index out of range", file ../../include/QtCore/../../src/corelib/tools/qlist.h, line 391
    Try to trace the lists you are using in the application.

  10. #9
    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: What happens after closing and before destruction?

    Quote Originally Posted by aamer4yu View Post
    Try to trace the lists you are using in the application.
    I would do it, but I'm not using QLists at the moment, and noteven objects that inherit from it.
    --
    raccoon29

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

  11. #10
    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: What happens after closing and before destruction?

    Of course you are. The mdi window keeps a list of its child windows. You are interacting with it when closing a child window. Maybe you simply shouldn't use the attribute. I suggest you take a look at the source code of the mdi framework and see what happens if you close a child window.

  12. #11
    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: What happens after closing and before destruction?

    Quote Originally Posted by wysota View Post
    Of course you are. The mdi window keeps a list of its child windows. You are interacting with it when closing a child window. Maybe you simply shouldn't use the attribute. I suggest you take a look at the source code of the mdi framework and see what happens if you close a child window.
    Yes,yes, you are right, I noticed it but only after the last post, and then I forgot to edit.
    Anyway I've given a look a the source like you suggest, but still the problem is in the shadow.
    I found the assert that fails, but still I don't understand why; I'm going to break my head for the second time trying to understand how that subwindows list index works

    EDIT: I've already tried to cutout the attribute, but the problem persists.
    Last edited by Raccoon29; 18th April 2008 at 18:35. Reason: user request
    --
    raccoon29

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

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.