<div>Hi Mike,</div><div> </div><div>I agree with your opion. Actually, I did backtrace. The message showed like "~qobject, qobject.cpp can not find." I guess that the pyqt try to delete an deleted object. </div><div>
 </div><div>If you have other ideas, please let me know.</div><div> </div><div>Thanks!</div><div> </div><div>Jian<br><br></div><div class="gmail_quote">On Fri, Jul 29, 2011 at 7:44 PM, Mike Ramirez <span dir="ltr"><<a href="mailto:gufymike@gmail.com">gufymike@gmail.com</a>></span> wrote:<br>
<blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" class="gmail_quote"><div><div></div><div class="h5">On Friday, July 29, 2011 04:20:27 PM Algis Kabaila wrote:<br>

> On Sat, 30 Jul 2011 08:18:58 AM Jian Ma wrote:<br>
> > Hi all,<br>
> ><br>
> > I created a QMenu object in a class. When I created it with menu =<br>
> > QMenu(self) and run the program, it sometimes got the "segmentation<br>
> > fault" after exit the program. When I created the object with menu =<br>
> > QMenu(), it didn't get this problem. I guess the reason is about the<br>
> > QMenu object ownership. In one case, the object is owned by PyQt. In<br>
> > other case, it is owned by Qt. I am not sure my guess. Can someone give<br>
> > some explanation? Below is some code segment.<br>
> ><br>
> > class DnDMenuListWidget(QListWidget):<br>
> >     ...<br>
> >     ...<br>
> ><br>
> >     def dropEvent(self, event):<br>
> >         ...<br>
> >         ...<br>
> >         menu = QMenu(self)    # using QMenu(self)<br>
> >         # menu = QMenu()      #  using QMenu()<br>
> >         ...<br>
> >         ...<br>
> ><br>
> > Thanks!<br>
><br>
> In Python in a class instantiation the instance name is automatically<br>
> passed in a parameter, usually in a named variable "self", so if QMenu is<br>
> a method of a class, a varible named "self" needs to be specified, hence<br>
> QMenu(self).<br>
><br>
> If Qmenu is used as a function outside of a class creation, the "self"<br>
> argument is not required, so for functions, hence QMenu().<br>
><br>
> For further information read up on class creation of Python (and class<br>
> instantiation and class instances).<br>
><br>
> Good luck,<br>
> OldAl.<br>
</div></div>> _______________________________________________<br>
<br>
You're right about this stuff for python, but wrong about in this usage. In<br>
this case self is the parent object that owns the QMenu() child. It's not a<br>
method of the parent object, but an attribute.<br>
<br>
i.e.<br>
<br>
class MainWindow(QMainWindow):<br>
  # your explanation<br>
  def __init__(self, parent=None):<br>
     # his usage.<br>
     self.menu = QMenu(self)<br>
<br>
Using QMenu() without self, just sets the menu's parent to None at<br>
instination.<br>
<br>
The problem is appears to bein the destruction of the parent. I'm not sure. It<br>
does sounds like the parent is being deystroyed before the child (like the<br>
discussion on the list a few months ago). I can't remember the subject or the<br>
fix, but I think the fix was to set the child objects parent to None before it<br>
the parent was destroyed.  This is an _I Think_.  Others who participated in<br>
that convo would be better at answering it.<br>
<br>
Mike<br>
<font color="#888888"><br>
--<br>
They are called computers simply because computation is the only significant<br>
job that has so far been given to them.<br>
_______________________________________________<br>
PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br>
</font></blockquote></div><br>