[PyQt] problem with abstract classes

Jim Bublitz jbublitz at nwinternet.com
Tue Aug 14 04:11:27 BST 2007


On Sunday 12 August 2007 07:20, Diez B. Roggisch wrote:
> Hi,
>
> I'm in the process of wrapping the irrlicht 3d engine. So far, things
> have been working smoothly. However, now I stumbled over a problem that
> so far has not been willing to be disappearing, intensive gdb-use
> notwithstanding.
>
> There is a pure abstract class in Irrlicht, IEventReceiver. It looks
> like this:
>
> //! Interface of an object which can receive events.
> class IEventReceiver
> {
> public:
>
> 	virtual ~IEventReceiver() {};
>
> 	//! called if an event happened. returns true if event was processed
> 	virtual bool OnEvent(SEvent event) = 0;
> };
>
> This class I wrapped in SIP this way:
>
>     class IEventReceiver /Abstract/ {
> %TypeHeaderCode
> #include <IEventReceiver.h>
> %End
>         public:
>       bool OnEvent(irr::SEvent event);
>         };
>

The line for the method OnEvent should be the same in the sip file as in the h 
file - sip needs to see the "= 0", and it makes no sense to add that unless 
the method is marked 'virtual'.

I'm not sure I follow the rest of the explanation (likely my fault), but my 
guess is that sip is generating code to call a method that isn't there (a 
pure virtual) - you haven't told sip the method doesn't (concretely) exist.

Jim



> Which seems to work fine. Now of course I'm having troubles subclassing
> this class in Python, which is the reason I created a dummy-implemntation
>
> namespace irr {
>    class PyIEventReceiver : public IEventReceiver {
>    public:
>      virtual ~PyIEventReceiver();
>      bool OnEvent(SEvent event);
>    };
> };
>
> It is declared in my SIP-file as this:
>
>     class PyIEventReceiver : irr::IEventReceiver {
>
>
>     public:
>       bool OnEvent(irr::SEvent event);
>     };
>
> I can subclass this class in python, and my SEvent-marshalling-code
> works fine as well, as the following test-script shows:
>
> class MyER(irrlicht.irr.PyIEventReceiver):
>      def OnEvent(self, event):
>          print event
>
> er = MyER()
>
> event = (irrlicht.irr.EET_MOUSE_INPUT_EVENT, 100, 100, .5, 1)
> er.OnEvent(event)
>
>
>
> But now if I set this IEventReceiver to my IrrlichtDevice, I get the
> following error (inside GDB):
>
> Program received signal EXC_BAD_ACCESS, Could not access memory.
> Reason: KERN_PROTECTION_FAILURE at address: 0x00000008
> 0x0297119f in irr::CIrrDeviceStub::postEventFromUser (this=0x141a8f0,
> event={EventType = EET_MOUSE_INPUT_EVENT, {GUIEvent = {Caller = 0x145,
> EventType = 247}, MouseInput = {X = 325, Y = 247, Wheel = 0, Event =
> EMIE_MOUSE_MOVED}, KeyInput = {Char = 325, Key = KEY_CRSEL, PressedDown
> = false, Shift = false, Control = false}, LogEvent = {Text = 0x145
> <Address 0x145 out of bounds>, Level = 247}, UserEvent = {UserData1 =
> 325, UserData2 = 247, UserData3 = 0}}}) at
> /Users/deets/Download/irrlicht-1.3.1/source/Irrlicht/MacOSX/../CIrrDeviceSt
>ub.cpp:164 164                     absorbed = UserReceiver->OnEvent(event);
> (gdb) p UserReceiver
> warning: RTTI symbol not found for class 'irr::NSOpenGLViewDeviceDelegate'
> $1 = (IEventReceiver *) 0x1492ec0
> Current language:  auto; currently c++
>
> UserReceiver here is a pointer to a IEventReceiver, which seems to be
> correctly set. I tried stepping into the code, but wasn't able to.
>
> This is with OSX 10.4, Python2.5, latest stable sip (4.7).
>
> Any suggestions? Am I doing something fundamentally wrong wrt
> implementation of C++-interfaces?
>
> Kind regards,
>
> Diez
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt


More information about the PyQt mailing list