[Qgis-developer] PyQGIS signal slot problem

Marco Hugentobler marco at hugis.net
Sat Apr 24 02:33:39 EDT 2010


Hi Martin

Hm, but in my case this would mean to insert the %ConvertToSubClassCode 
directive into the sip file for QGraphicsView (that comes from PyQt). Is there 
a possibility to use  %ConvertToSubClassCode without changing PyQt?

Thanks,
Marco

Am Samstag, 24. April 2010 02.07:03 schrieb Martin Dobias:
> 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
> 


-- 
Dr. Marco Hugentobler
HUGIS GmbH
Webereistr. 66
CH-8134 Adliswil
marco at hugis.net
www.hugis.net
Technical Advisor QGIS Project Steering Committee


More information about the Qgis-developer mailing list