[PyQt] crash in sip.cast
Phil Thompson
phil at riverbankcomputing.com
Wed Mar 17 19:48:45 GMT 2010
On Wed, 17 Mar 2010 11:31:50 -0700, Nathan Cournia <cournia at gmail.com>
wrote:
> 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?
Implement %ConvertToSubClassCode for all your QObject subclasses.
getWidget() will then return a FooWidget.
Phil
More information about the PyQt
mailing list