Calling processEvents() doesn't trigger deffered deletion. The application really needs to enter the event loop.
Calling processEvents() doesn't trigger deffered deletion. The application really needs to enter the event loop.
How can I force it? Is there any way?
Here is the problem:
There is application that handles text commands. I have a Qt widget that is closed with some close * command. Qt::WA_DeleteOnClose attribute is set for that widget, it receives closeEvent, but destructor for that object is called later (I guess on idle).
If I have two commands
close *;
get something;
the program crashes because "get something" is called before destructor for that widget, so widget still receives events and it tries to access data deleted by close * command. I would like to force Qt to delete all pending objects after command completion.
I guess previously it was entering event processing loop, but something is changed.
Any ideas how to make it work?
Thanks.
Last edited by axe; 18th August 2011 at 09:12.
Why would you want to force it?
Then either schedule execution of "get something" and return to the event loop or simply have the closeEvent for the widget (or some other appropriate place) contain code that will set a flag that is checked before the widget tries to access this data. Or use one of available smart pointer classes.the program crashes because "get something" is called before destructor for that widget, so widget still receives events and it tries to access data deleted by close * command. I would like to force Qt to delete all pending objects after command completion.
wysota
The problem appeared after updating Qt version from 4.3.3 to 4.7.2. I wouldn't like making such changes, the code is really huge and every simple change may result in thousands of bugs. I would like to fix the problem with minimum amount of changes. I guess previously Qt was forced to delete the object by calling sendPostedEvents() (at least comment says that), but currently this doesn't work.
Here is the code
Qt Code:
// Send queued events (including deferred deletions) to all QObjects // unless we have to preserve view objects if (deleteImmediately)To copy to clipboard, switch view to plain text mode
This code looks strange to me, however this is what we have and this is what was working before.
Do you mean there is no way to force it?
Last edited by axe; 18th August 2011 at 10:22.
May be I didn't get the complete picture yet, if you want to delete immediately, can't you just call delete on the object directly, instead of calling deleteLater() on the object.
(few posts above)May be I didn't get the complete picture yet, if you want to delete immediately, can't you just call delete on the object directly, instead of calling deleteLater() on the object.
I can replace this function call with manual deletion, but I'm not sure what will happen if Qt will try to delete this deferred object. If I remove DeleteOnClose attribute then I would need to delete all objects manually, but the code is so huge that it's really impossible to do not forget about anything. I wouldn't like making such changes.
Bookmarks