Re: [PyQt] problem with abstract classes
Giovanni Bajo schrieb: On 12/08/2007 16.20, Diez B. Roggisch wrote: Any suggestions? Am I doing something fundamentally wrong wrt implementation of C++-interfaces? Please post a minimal, complete example that reproduces your problem. Otherwise, it's a little hard to help you... I know... So I tried to come up with a smaller example. However, it's not showing the same, but another problem. Until that is fixed, I think investigating the old problem is pretty much useless. The attached project tries to model the situation I have in my real app. It compiles runs under my Mac. Essentially all I try to do is to create a interface in C++ (IEventReceiver), a subclass (PyIEventReceiver) to overload the pure virtual methods of the base-interface so it can be overloaded in python and a test-class that invokes the OnEvent-method in a previously set IEventReceiver implementation. Then in the python-test-script, I try and instantiate the test-object, and subclass the PyIEventReceiver. The latter is the problem. When passing that into the test-object and invoke the test-method, I don't get the overloaded method invoked. How do I achieve that? I'm not sure if the two problems are related - but until this works, it's moot to try and make the other problem go away. Kind regards, Diez SIPTest.tgz Description: GNU Zip compressed data ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] problem with abstract classes
On Tuesday 14 August 2007 8:47 am, Diez B. Roggisch wrote: Giovanni Bajo schrieb: On 12/08/2007 16.20, Diez B. Roggisch wrote: Any suggestions? Am I doing something fundamentally wrong wrt implementation of C++-interfaces? Please post a minimal, complete example that reproduces your problem. Otherwise, it's a little hard to help you... I know... So I tried to come up with a smaller example. However, it's not showing the same, but another problem. Until that is fixed, I think investigating the old problem is pretty much useless. The attached project tries to model the situation I have in my real app. It compiles runs under my Mac. Essentially all I try to do is to create a interface in C++ (IEventReceiver), a subclass (PyIEventReceiver) to overload the pure virtual methods of the base-interface so it can be overloaded in python and a test-class that invokes the OnEvent-method in a previously set IEventReceiver implementation. Then in the python-test-script, I try and instantiate the test-object, and subclass the PyIEventReceiver. The latter is the problem. When passing that into the test-object and invoke the test-method, I don't get the overloaded method invoked. How do I achieve that? I'm not sure if the two problems are related - but until this works, it's moot to try and make the other problem go away. Do as Jim said and make sure the declaration of IEventReceiver::OnEvent() is the same in the .h and .sip files (see attached). Also remove the /Abstract/ annotation (for your example at least). Including it means that there are *other* abstract functions which I'm not going to tell you about. With the new .sip file I get the following output from running your test... overloaded event: 200 overloaded event: 100 Phil // Define the SIP wrapper to the irrlicht library %Module siptest 0 // TODO: figure out // if there is a way to only include that // in the enum source %ModuleHeaderCode #include test.h %End class IEventReceiver { public: virtual void OnEvent(int) = 0; }; class PyIEventReceiver : IEventReceiver { public: void OnEvent(int); }; class IEventReceiverTest { public: void test(); void setReceiver(IEventReceiver *); }; ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] problem with abstract classes
On 14/08/2007 9.47, Diez B. Roggisch wrote: Essentially all I try to do is to create a interface in C++ (IEventReceiver), a subclass (PyIEventReceiver) to overload the pure virtual methods of the base-interface so it can be overloaded in python and a test-class that invokes the OnEvent-method in a previously set IEventReceiver implementation. You don't need PyIEventReceiver at all. You can directly subclass IEventReceiver, if that's what you want to achieve. /Abstract/ is meant to force SIP *NOT* to allow instantiations of the class. That's not what you want. Then in the python-test-script, I try and instantiate the test-object, and subclass the PyIEventReceiver. The latter is the problem. When passing that into the test-object and invoke the test-method, I don't get the overloaded method invoked. You didn't define them as virtual in the sip file... what did you expect? :) Define them as virtual (and even add the = 0 where appropriate) and you will get the right behaviour. -- Giovanni Bajo ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] problem with abstract classes
On 12/08/2007 16.20, Diez B. Roggisch wrote: Any suggestions? Am I doing something fundamentally wrong wrt implementation of C++-interfaces? Please post a minimal, complete example that reproduces your problem. Otherwise, it's a little hard to help you... -- Giovanni Bajo ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] problem with abstract classes
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: 0x0008 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 listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[PyQt] problem with abstract classes
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); }; 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: 0x0008 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/../CIrrDeviceStub.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 listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt