[PyQt] problem with abstract classes

Phil Thompson phil at riverbankcomputing.co.uk
Tue Aug 14 09:30:05 BST 2007

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.sip
Type: text/x-c++src
Size: 442 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20070814/c1a29a38/test.bin

More information about the PyQt mailing list