No way to remove KAction from KActionCollection

Simon Hausmann hausmann at kde.org
Fri Nov 21 18:00:30 GMT 2003


On Fri, Nov 21, 2003 at 06:48:25PM +0100, Tobias Koenig wrote:
> Hi,
> 
> atm there is no way to remove a KAction object from its parent
> KActionCollection without deleting it.
> 
> When calling actionCollection()->takeItem( action ) the action is only
> removed from the internal QAsciiDict of KActionCollection, but the
> KAction still has a valid pointer to the collection.
> When the application is quit, the KAction is destroyed and tries to
> unregister itsself with its m_parentCollection pointer (which is not
> valid anymore), so it tries to access an invalid object.
> 
> Any idea how to solve this?
> Maybe adding an additional method
>   void setActionCollection( KActionCollection* )
> so the m_parentCollection can set to 0 explicitely?

How about this (untested):

Index: kactioncollection.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kactioncollection.cpp,v
retrieving revision 1.310
diff -u -p -b -r1.310 kactioncollection.cpp
--- kactioncollection.cpp	28 May 2003 02:49:23 -0000	1.310
+++ kactioncollection.cpp	21 Nov 2003 17:59:47 -0000
@@ -316,7 +316,10 @@ void KActionCollection::_insert( KAction
 
 void KActionCollection::_remove( KAction* action )
 {
-  delete _take( action );
+  KAction *a = _take( action );
+  if ( a )
+    a->m_parentCollection = 0;
+  delete a;
 }
 
 KAction* KActionCollection::_take( KAction* action )

Simon




More information about the kde-core-devel mailing list