Page 1 of 3 123 LastLast
Results 1 to 20 of 46

Thread: What happens after closing and before destruction?

  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 "

  13. #12
    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?

    Let's try from the beginning... Could you describe the goal you are trying to obtain? Maybe instead of trying to fix your solution we'll find some other solution that works.

  14. #13
    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?

    Could you describe the goal you are trying to obtain?
    My goal is to close the windows without the program be destroyed

    The trouble is that the description requires many "if", anyway here follows a "once for all" description.

    =ENVIRONMENT=
    It is a QMdiArea workspace.
    There are three QMdiSubWindows: ViewArticles that makes open Article that makes open Manager. I say "makes open" because between them there are no dependencies, no one of them is parent of the other: they all refer to the master class CViewports which manage them all just opening and closing them.
    Every QMdiSubWindow has the WA_DeleteOnClose attribute.

    =PROBLEM=
    Now, when Article calls Manager (to do a quick search), the same Article becomes a wandering bomb, because if it get closed, the whole program explodes with the famous error:
    ASSERT failure in QList<T>::at: "index out of range", file ../../include/QtCore/../../src/corelib/tools/qlist.h, line 391
    =DEBUG CLUES=
    -Opened Article, opened Manager, closed Manager (now Article is expected to boom on close, but...), made lost focus to the Article window (so give focus to ViewArticles, or just switch to another program and then come back) and Article get defused and even closed the program continues normally.

    -Other windows (out of Article) call Manager, and all of them become wanding bombs just like Article.

    -If Manager get not called all works as expected.

    -When closing Article before assertion failed, the number of opened windows in QMdiArea::subWindowList seems to be right (=2).


    These are the main clues I found, I would post some code too, but there are over twenty files, so I'll post them on request if needed.
    But anyway what is important and that I really can't understand is why the loss of the focus heals the error!

    Every question is welcome, just I'd like to know why all this!
    Last edited by Raccoon29; 23rd April 2008 at 10:14. Reason: updated contents
    --
    raccoon29

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

  15. #14
    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?

    One step at a time...

    Let's try with a minimal application that consists of an mdiarea that has a child window that can open other windows in the mdi space using a button or something like that. No special attributes or anything. When you have that done and verify it does not crash, you can continue with putting some logic of yours there.

  16. #15
    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?

    I'm trying to reproduce the error in a minimal application as you suggested, but still the problem has not shown itself.
    I attached the source of the minimal application, maybe in the meanwhile some one of you could make the error raise, playing around...
    Attached Files Attached Files
    --
    raccoon29

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

  17. #16
    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?

    If it works fine then try to isolate some other part of your code and implement or paste it into the test environment you just built.

  18. #17
    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
    If it works fine then try to isolate some other part of your code and implement or paste it into the test environment you just built.
    Ok, I'm trying it.

    Meanwhile, do you have any sort of idea of what is this dued to? Or do you have any idea on why the focus should heal it, what sort of signals could emit the focus?
    --
    raccoon29

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

  19. #18
    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?

    If I had, I would have already told you.

  20. #19
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What happens after closing and before destruction?

    Hi,
    I'm using Qt::WA_DeleteOnClose with MDI sub windows and it works fine, so i think it's some bug in your code(not qt's).
    Qt docs says that mdi sub window should have set Qt::WA_DeleteOnClose because QMdiArea won't work properly.
    When you create your own subwindow, you must set the Qt::WA_DeleteOnClose widget attribute if you want the window to be deleted when closed in the MDI area. If not, the window will be hidden and the MDI area will not activate the next subwindow.
    However i think it may be a problem with Qt::WA_DeleteOnClose defined twice - on QMdiSubWindow itself and on widget contained by this QMdiSubWindow.
    This could produce a crash because hiding subwindow deletes subwindow & contained widget & then widget is removed once again.

    I'm not sure about this, but if QMdiSubWindow have Qt::WA_DeleteOnClose attribute set(and it probably have set it by default), you shouldn't set it on widget of sub window.
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  21. #20
    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?

    Quote Originally Posted by mchara View Post
    I'm not sure about this, but if QMdiSubWindow have Qt::WA_DeleteOnClose attribute set(and it probably have set it by default), you shouldn't set it on widget of sub window.
    If the widget is not deleted explicitely in the destructor by calling delete on it, it shouldn't be a problem - QObject will "disconnect" the object from the list of its children so it shouldn't be deleted again by the parent as it has no parent anymore.

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.