I have code that deletes deferred object by calling sendPostedEvents for Qt 4.3.3, but this code doesn't work for Qt 4.7.2. Also I tried to make a simple application that works and I couldn't make it work even with Qt 4.3.3, sendPostedEvents doesn't call any destructors. It's difficult to track everything what is going on in original application before it calls sendPostedEvents and deletes deferred object, does anybody know anything about it? In what situations it can invoke deferred delete? Any useful information that will help me to debug?
Can it depend on some project options or predefined macros? Is there any known bug? Anything...
Added after 1 40 minutes:
Looks like sendPostedEvents delete deferred objects only if it's not called from Qt event handler. Our events are coming from Tcl, so they are not called from Qt main event loop, seems that this is the reason that it works, but here is another problem.
This code
Dialog::~Dialog() {
std::cout << "~test()" << std::endl;
}
int main(int argc, char* argv[]) {
Dialog* dlg = new Dialog();
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->show();
dlg->close();
std::cout << "before sendPostedEvents()" << std::endl;
std::cout << "after sendPostedEvents()" << std::endl;
return app.exec();
}
Dialog::~Dialog() {
std::cout << "~test()" << std::endl;
}
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
Dialog* dlg = new Dialog();
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->show();
dlg->close();
std::cout << "before sendPostedEvents()" << std::endl;
QCoreApplication::sendPostedEvents();
std::cout << "after sendPostedEvents()" << std::endl;
return app.exec();
}
To copy to clipboard, switch view to plain text mode
prints
before sendPostedEvents()
after sendPostedEvents()
~test()
but as soon as I add closeEvent handler and call deleteLater() in that handler function sendPostedEvents starts deleting deferred objects.
deleteLater();
}
void Dialog::closeEvent(QCloseEvent* ev) {
deleteLater();
QWidget::closeEvent(ev);
}
To copy to clipboard, switch view to plain text mode
before sendPostedEvents()
~test()
after sendPostedEvents()
Can anybody explain what the hell is going on there? I have no idea what's that. Is it just a bug? Can I use that workaround?
How does this work? Shouldn't Qt call deleteLater() automatically, after closeEvent is accepted if CloseOnDelete attribute is set?
Bookmarks