Thanks for the reply. Perhaps you can tell me what's the best way to handle the following situation:<br><br>// in C++<br>class FooWidget: public QWidget<br>{<br> //...<br> void bar();<br> //...<br>};<br><br>// the QWidget this function returns is more than likely a FooWidget<br>
QWidget* getWidget();<br><br>In SIP, I wrap both FooWidget and getWidget. In Python, I do:<br><br># the returned C++ object is wrapped as a PyQt4.QtGui.QWidget, not a FooWidget<br>a = getWidget();<br><br># doesn't work, can't find method<br>
a.bar()<br><br># crashed as of SIP 4.10<br>b = sip.cast(a, FooWidget)<br><br># should work?<br>b.bar()<br><br>Is this a good use of sip.cast or is there a better way to approach this problem?<br><br>Thanks again,<br><br>nathan<br>
<br><div class="gmail_quote">On Wed, Mar 17, 2010 at 2:33 AM, Phil Thompson <span dir="ltr"><<a href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Tue, 16 Mar 2010 18:32:57 -0700, Nathan Cournia <<a href="mailto:cournia@gmail.com">cournia@gmail.com</a>><br>
wrote:<br>
<div><div></div><div class="h5">> Hi,<br>
><br>
> The following script segfaults:<br>
><br>
> import sys<br>
> import sip<br>
> from PyQt4.QtGui import *<br>
><br>
> a = QApplication(sys.argv)<br>
><br>
> # create a menu<br>
> b = QMenu()<br>
><br>
> # cast it to a widget<br>
> c = sip.cast(b, QWidget)<br>
><br>
> # cast the widget, which is really a menu, back to a menu.<br>
> # this line crashes<br>
> d = sip.cast(c, QMenu)<br>
><br>
> Here's the stack trace...<br>
><br>
> #0 0x5573cf09 in cast (self=0x0, args=0x83c570c) at siplib.c:907<br>
> #1 0x555eccf0 in PyCFunction_Call () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #2 0x5566465a in call_function () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #3 0x55660f83 in PyEval_EvalFrameEx () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #4 0x55662980 in PyEval_EvalCodeEx () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #5 0x5565b76c in PyEval_EvalCode () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #6 0x5568a3a2 in run_mod () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #7 0x5568a328 in PyRun_FileExFlags () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #8 0x556562f3 in builtin_execfile () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #9 0x555eccf0 in PyCFunction_Call () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #10 0x5566465a in call_function () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #11 0x55660f83 in PyEval_EvalFrameEx () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #12 0x55662980 in PyEval_EvalCodeEx () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #13 0x5565b76c in PyEval_EvalCode () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #14 0x5566620a in exec_statement () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #15 0x5565ed88 in PyEval_EvalFrameEx () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #16 0x55662980 in PyEval_EvalCodeEx () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #17 0x555d61ca in function_call () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #18 0x555a5810 in PyObject_Call () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #19 0x555bbeae in instancemethod_call () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #20 0x555a5810 in PyObject_Call () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
> #21 0x555a5e03 in PyObject_CallMethodObjArgs () from<br>
> /usr/apps/python/python-2.6.1/lib/libpython2.6.so.1.0<br>
><br>
> The following line in siplib.c:907:cast() is crashing:<br>
><br>
> if ((addr = sip_api_get_cpp_ptr(sw, type->type)) == NULL)<br>
> return NULL;<br>
><br>
> Above, "type" (the one left of ->) is NULL.<br>
><br>
> I'm using sip-4.10, PyQt-x11-gpl-4.7, and Qt 4.5.3.<br>
><br>
> Am I using sip.cast incorrectly? Any help would be greatly appreciated.<br>
<br>
</div></div>It's a bug - fixed in tonight's snapshot...<br>
<br>
...however it is very, very rare that you would need to use cast().<br>
<font color="#888888"><br>
Phil<br>
</font></blockquote></div><br>