KAutoPointer: a new autoptr class for QPointer

Lubos Lunak l.lunak at suse.cz
Thu Jul 23 14:37:42 BST 2009


On Monday 13 of July 2009, Frank Osterfeld wrote:
> On Friday 10 July 2009 12:36:07 Lubos Lunak wrote:
> >  It appears to be also technically wrong, since when exec() in
> > ParentWidget::slotDoSomething() is called, the control flow should
> > continue by returning from it. That part actually confuses me a bit,
> > since I don't know what exactly happens behind the scenes, but I assume
> > that quit() somehow destroys some data including the dialog and then
> > returns control, and in that case this is just patching over a small
> > problem and asking for a much bigger one. If quit() really does this,
> > then it is a bug. First
>
> It's not just quit, anything that deletes your widget causes the problem.

 It does not cause the problem, it is the problem. If they are my widgets, I 
delete them, not some random anything.

> > ParentWidget::slotDoSomething() should return control to the main loop
> > and from there the exit and cleanup should really happen.
>
> Can you elaborate how that would look like in code? I.e. how
> slotDoSomething() should handle the case that quit() was called or konqueror
> wants to delete the widget in between? 

 There is no need for any special handling in slotDoSomething(), because it is 
not broken. The thing that needs fixing is whatever deletes the 'this' widget 
while it is still in use (which it is, since the control flow is in 
this->slotDoSomething()).

> It's a "make sure the dialog is deleted, one way or another" pointer that
> combines the ownership model of QObject with std::auto_ptr-like behavior.
> It might be too much of a special case to justify another pointer class,
> but then we need another solution.

  Arguing that at least something random should delete the stuff is like 
thinking that garbage collection magically fixes all resource problems. The 
solution is to fix the bug or at least show that it can't be fixed and a 
workaround is needed. Not even the latter has happened, you just said "hey, 
something deleted my widget behind my back, I propose this class as a 
workaround".

-- 
Lubos Lunak
KDE developer
--------------------------------------------------------------
SUSE LINUX, s.r.o.   e-mail: l.lunak at suse.cz , l.lunak at kde.org
Lihovarska 1060/12   tel: +420 284 084 672
190 00 Prague 9      fax: +420 284 028 951
Czech Republic       http://www.suse.cz




More information about the kde-core-devel mailing list