[PyQt] crash in sip.cast

Nathan Cournia cournia at gmail.com
Wed Mar 17 18:31:50 GMT 2010


Thanks for the reply.  Perhaps you can tell me what's the best way to handle
the following situation:

// in C++
class FooWidget: public QWidget
{
  //...
  void bar();
  //...
};

// the QWidget this function returns is more than likely a FooWidget
QWidget* getWidget();

In SIP, I wrap both FooWidget and getWidget.  In Python, I do:

# the returned C++ object is wrapped as a PyQt4.QtGui.QWidget, not a
FooWidget
a = getWidget();

# doesn't work, can't find method
a.bar()

# crashed as of SIP 4.10
b = sip.cast(a, FooWidget)

# should work?
b.bar()

Is this a good use of sip.cast or is there a better way to approach this
problem?

Thanks again,

nathan

On Wed, Mar 17, 2010 at 2:33 AM, Phil Thompson
<phil at riverbankcomputing.com>wrote:

> On Tue, 16 Mar 2010 18:32:57 -0700, Nathan Cournia <cournia at gmail.com>
> wrote:
> > Hi,
> >
> > The following script segfaults:
> >
> > import sys
> > import sip
> > from PyQt4.QtGui import *
> >
> > a = QApplication(sys.argv)
> >
> > # create a menu
> > b = QMenu()
> >
> > # cast it to a widget
> > c = sip.cast(b, QWidget)
> >
> > # cast the widget, which is really a menu, back to a menu.
> > # this line crashes
> > d = sip.cast(c, QMenu)
> >
> > Here's the stack trace...
> >
> > #0  0x5573cf09 in cast (self=0x0, args=0x83c570c) at siplib.c:907
> > #1  0x555eccf0 in PyCFunction_Call () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #2  0x5566465a in call_function () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #3  0x55660f83 in PyEval_EvalFrameEx () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #4  0x55662980 in PyEval_EvalCodeEx () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #5  0x5565b76c in PyEval_EvalCode () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #6  0x5568a3a2 in run_mod () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #7  0x5568a328 in PyRun_FileExFlags () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #8  0x556562f3 in builtin_execfile () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #9  0x555eccf0 in PyCFunction_Call () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #10 0x5566465a in call_function () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #11 0x55660f83 in PyEval_EvalFrameEx () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #12 0x55662980 in PyEval_EvalCodeEx () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #13 0x5565b76c in PyEval_EvalCode () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #14 0x5566620a in exec_statement () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #15 0x5565ed88 in PyEval_EvalFrameEx () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #16 0x55662980 in PyEval_EvalCodeEx () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #17 0x555d61ca in function_call () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #18 0x555a5810 in PyObject_Call () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #19 0x555bbeae in instancemethod_call () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #20 0x555a5810 in PyObject_Call () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> > #21 0x555a5e03 in PyObject_CallMethodObjArgs () from
> > /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0
> >
> > The following line in siplib.c:907:cast() is crashing:
> >
> >     if ((addr = sip_api_get_cpp_ptr(sw, type->type)) == NULL)
> >         return NULL;
> >
> > Above, "type" (the one left of ->) is NULL.
> >
> > I'm using sip-4.10, PyQt-x11-gpl-4.7, and Qt 4.5.3.
> >
> > Am I using sip.cast incorrectly?  Any help would be greatly appreciated.
>
> It's a bug - fixed in tonight's snapshot...
>
> ...however it is very, very rare that you would need to use cast().
>
> Phil
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100317/9f962208/attachment.html>


More information about the PyQt mailing list