Gideon crashes when opening a file in MDI mode
Simon Hausmann
hausmann at kde.org
Wed May 22 09:54:02 UTC 2002
On Wed, May 22, 2002 at 10:08:49AM +0200, Bernd Gehrmann wrote:
> On Wednesday 22 May 2002 08:59, Simon Hausmann wrote:
>
> > Hm, yes. But it takes more than that. The slot connected to the
> > part's destroyed() signal calls removePart() with sender(). If
> > removedPart would call setManager, then in that case it would
> > call it on a partially dead object, as the destroyed() signal is
> > emitted from within the ~Object destructor. I guess it would still
> > work given that the object is allocated as one big chunk of memory,
> > freed after the last dtor, but that's a hack ;-)
>
> The patch again... someday I'll learn to use KMail ;-)
>
> This calls removePart() from the Part destructor.
> While ~Part is executed, the object is still valid. That
> means, at this place a method invocation on the part object should
> be no problem.
Excellent idea, re-using the already existing dependency.
For reference the other idea with ~part emitting partDestroyed()
attached as patch, but I prefer your approach actually. (I saw your
mail just when I switched to the mutt terminal to send out a mail
with that patch :)
Simon
-------------- next part --------------
Index: part.cpp
===================================================================
RCS file: /home/kde/kdelibs/kparts/part.cpp,v
retrieving revision 1.113
diff -u -p -b -r1.113 part.cpp
--- part.cpp 2002/04/29 00:23:13 1.113
+++ part.cpp 2002/05/22 07:47:24
@@ -126,6 +126,9 @@ Part::Part( QObject *parent, const char*
Part::~Part()
{
kdDebug(1000) << "Part::~Part " << this << endl;
+
+ emit partDestroyed( this );
+
if ( m_widget )
{
// We need to disconnect first, to avoid calling it !
Index: part.h
===================================================================
RCS file: /home/kde/kdelibs/kparts/part.h,v
retrieving revision 1.90
diff -u -p -b -r1.90 part.h
--- part.h 2002/03/08 17:42:06 1.90
+++ part.h 2002/05/22 07:47:25
@@ -196,6 +196,10 @@ signals:
*/
void setStatusBarText( const QString & text );
+ /**
+ * Emitted by the Part destructor.
+ */
+ void partDestroyed( KParts::Part *part );
protected:
/**
Index: partmanager.cpp
===================================================================
RCS file: /home/kde/kdelibs/kparts/partmanager.cpp,v
retrieving revision 1.56
diff -u -p -b -r1.56 partmanager.cpp
--- partmanager.cpp 2002/03/29 23:13:35 1.56
+++ partmanager.cpp 2002/05/22 07:47:25
@@ -300,7 +300,7 @@ void PartManager::addPart( Part *part, b
if ( d->m_parts.findRef( part ) != -1 ) // don't add parts more than once :)
return;
- connect( part, SIGNAL( destroyed() ), this, SLOT( slotObjectDestroyed() ) );
+ connect( part, SIGNAL( partDestroyed( KParts::Part * ) ), this, SLOT( slotObjectDestroyed() ) );
d->m_parts.append( part );
@@ -335,10 +335,13 @@ void PartManager::removePart( Part *part
kdFatal(1000) << QString("Can't remove part %1, not in KPartManager's list.").arg(part->name()) << endl;
return;
}
- disconnect( part, SIGNAL( destroyed() ), this, SLOT( slotObjectDestroyed() ) );
+ disconnect( part, SIGNAL( partDestroyed( KParts::Part * ) ), this, SLOT( slotObjectDestroyed() ) );
//Warning. The part could be already deleted
//kdDebug(1000) << QString("Part %1 removed").arg(part->name()) << endl;
+
+ part->setManager( 0 );
+
d->m_parts.removeRef( part );
emit partRemoved( part );
@@ -358,7 +361,7 @@ void PartManager::replacePart( Part * ol
kdFatal(1000) << QString("Can't remove part %1, not in KPartManager's list.").arg(oldPart->name()) << endl;
return;
}
- disconnect( oldPart, SIGNAL( destroyed() ), this, SLOT( slotObjectDestroyed() ) );
+ disconnect( oldPart, SIGNAL( partDestroyed( KParts::Part * ) ), this, SLOT( slotObjectDestroyed() ) );
d->m_parts.removeRef( oldPart );
emit partRemoved( oldPart );
More information about the KDevelop-devel
mailing list