[PyQt] Calling subclass-overridden methods from C++

Phil Thompson phil at riverbankcomputing.com
Tue Oct 7 15:29:04 BST 2014


On 07/10/2014 3:24 pm, Alessandro Pasotti wrote:
> 2014-10-07 16:11 GMT+02:00 Phil Thompson <phil at riverbankcomputing.com>:
>> On 07/10/2014 2:34 pm, Alessandro Pasotti wrote:
>>> 
>>> 2014-10-07 15:31 GMT+02:00 Alessandro Pasotti <apasotti at gmail.com>:
>>>> 
>>>> Hi,
>>>> 
>>>> I'm currently busy trying to add python plugins support to the 
>>>> server
>>>> side of QGIS (http://www.qgis.org).
>>>> 
>>>> Basically, I've written all the c++ part, and python plugins are
>>>> successfully loaded and started, what I still don't understand is 
>>>> how
>>>> to call from C++ code the Python overridden methods.
>>>> 
>>>> In C++ I have a class QgsServerFilter with a default empty method 
>>>> for
>>>> requestReady()
>>>> 
>>> 
>>> Sorry: silly TAB in Gmail.
>>> 
>>> In the Python plugin I do something like:
>>> 
>>> class HelloServer(QgsServerFilter):
>>>     def requestReady()
>>>         pass
>>> 
>>> 
>>> then I pass the HelloServer instance to C++ (stored into "filter") 
>>> and
>>> later on C++ calls:
>>> 
>>> filter->requestReady()
>>> 
>>> but instead of calling HelloServer->requestReady() the base (empty)
>>> method is called.
>>> 
>>> What am I doing wrong?
>> 
>> 
>> Impossible to say with the information you have provided.
> 
> This is good news, it means that my approach wasn't completely wrong,
> here some details:
> 
> The relevant code can be found here (C++):
> 
> The QgsServerFilter class:
> https://github.com/elpaso/QGIS/blob/serverplugins-iface/src/mapserver/qgsserverfilter.h
> 
> main application C++ calls:
> https://github.com/elpaso/QGIS/blob/serverplugins-iface/src/mapserver/qgis_map_serv.cpp#L366
> 
> and here (SIP):
> https://github.com/elpaso/QGIS/blob/serverplugins-iface/python/server/qgsserverfilter.sip
> 
> The test plugin Python code is here:
> https://dpaste.de/SOg6

You can't override non-virtual functions.

Phil


More information about the PyQt mailing list