Hi all,
I'm porting application from older version of Qt to 4.7.2 and I found one problem there.
deleteLater() function is supposed to schedule object for deletion and object should be deleted when control next time enters to the event processing loop, but it doesn't work for me.
Here is the code
test *t = new test();
t->show();
std::cout << "before deleteLater()" << std::endl;
t->deleteLater();
std::cout << "after deleteLater()" << std::endl;
std::cout << "after processEvents()" << std::endl;
test *t = new test();
t->show();
std::cout << "before deleteLater()" << std::endl;
t->deleteLater();
std::cout << "after deleteLater()" << std::endl;
QCoreApplication::sendPostedEvents();
QCoreApplication::processEvents();
std::cout << "after processEvents()" << std::endl;
To copy to clipboard, switch view to plain text mode
Class test is derived from QDialog. It prints test() in constructor and ~test() in destructor.
This code gives the following output
test()
before deleteLater()
after deleteLater()
after processEvents()
~test()
According to Qt documentation it should delete the object before last cout, am I right? Looks like a bug in Qt, does anybody know anything about it? Any workaround?
Of course I could do manual delete, but application is huge and it would require too much changes, I wouldn't like to change too much things as it may cause another problems.
Thanks.
Bookmarks