[Qgis-developer] PyQGIS signal slot problem

Martin Dobias wonder.sk at gmail.com
Fri Apr 23 20:07:03 EDT 2010


Hi Marco

On Fri, Apr 23, 2010 at 11:57 PM, Marco Hugentobler <marco at hugis.net> wrote:
> Hi Python experts
>
> I'm trying to connect to the signal QgisInterface::composerAdded(
> QgsComposerView* v ) with python. However, I only get a QGraphicsView object
> (so the parent class of composer view), not a QgsComposerView instance. Is
> there some sip magic that needs to be done?

Indeed, some sip magic is needed: sip is informed about the subclasses
by using %ConvertToSubClassCode directive, see [1] for details. It has
been used within some PyQGIS classes and their derived classes, for
example QgsMapLayer, QgsMapTool, QgsMapCanvas and some others.

I think the best way how to discriminate between parent and derived
classes is by directly querying the instance which type it belongs to
(e.g. calling its type() or a similar function). If that is not
possible, dynamic_cast comes as a rescue, though it depends on RTTI
which may not be available and may cause some trouble.

[1] http://www.riverbankcomputing.co.uk/static/Docs/sip4/directives.html


Bye
Martin


More information about the Qgis-developer mailing list