No way to remove KAction from KActionCollection

David Faure dfaure at klaralvdalens-datakonsult.se
Fri Nov 21 18:02:33 GMT 2003


On Friday 21 November 2003 18:48, 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.
Oh. Ouch. IMHO that's a bug in takeItem. Hmm it's called take().

> 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?
Yes, fix take() to set m_parentCollection to 0 if it was "this"
(like KActionCollection::~KActionCollection does)

This should be quite safe, especially since take was marked as deprecated for
quite some time, and was only undeprecated recently for some kdesktop need.

> Maybe adding an additional method
>   void setActionCollection( KActionCollection* )
> so the m_parentCollection can set to 0 explicitely?
Ouch, please not, that's opening to more inconsistencies. 

-- 
David Faure -- faure at kde.org, dfaure at klaralvdalens-datakonsult.se
Qt/KDE/KOffice developer
Klarälvdalens Datakonsult AB, Platform-independent software solutions




More information about the kde-core-devel mailing list