[Qgis-developer] Syntax for using QList<QgsMapLayer *> signal in python

Larry Shaffer larrys at dakotacarto.com
Thu Apr 19 12:32:28 EDT 2012


Hi Tim,

On Thu, Apr 19, 2012 at 3:33 AM, Tim Sutton <lists at linfiniti.com> wrote:

> Hi
>
> On Thu, Apr 19, 2012 at 11:28 AM, Tim Sutton <lists at linfiniti.com> wrote:
> > Hi
> >
> > On Thu, Apr 19, 2012 at 11:14 AM, Denis Rouzaud <denis.rouzaud at gmail.com>
> wrote:
> >> I would try
> >> SIGNAL("layersWillBeRemoved(QStringList)")
> >>
> >
> > Oh but its not a string list that the signal is emitting but rather a
> > QList of pointers to map layers?
> >
>
> Oh sorry I see I was the source of confusion with my python snippet -
> yes it is the added slot I am interested in.
>

Well, I'm no PyQt wizard, but did you try:

Decorating your slot?

    @pyqtSlot(list)
    def getLayers(self, layers):
        do stuff


Or maybe define it in the connection? (i.e. add [list]):

    QgsMapLayerRegistry.instance().layersWillBeRemoved[list].connect(self.
getLayers)

Seems QList should be auto-converted to Python list type anyhow by PyQt.


Does the QgsMapLayerRegistry.instance() need assigned to a variable before
making a connection?

Another silly question: does getLayers() have enough parameters?



> >> On 04/19/2012 11:09 AM, Tim Sutton wrote:
> >>
> >> Hi All
> >>
> >> Does anyone know the appropriate way to connect to the new
> >> QgsMapLayerRegistry signal I added in python:
> >>
> >> void layersAdded( QList<QgsMapLayer *> theMapLayers );
> >>
> >> I tried:
> >>
> >>             QtCore.QObject.connect(QgsMapLayerRegistry.instance(),
> >>
> >> QtCore.SIGNAL('layersWillBeRemoved(QList<QgsMapLayer*>)'),
> >>                     self.getLayers)
> >>
> >> But that doesnt seem to be hitting my slot.
> >>
>

Regards,

Larry Shaffer
Dakota Cartography
Black Hills, South Dakota
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20120419/ac7fb337/attachment.html


More information about the Qgis-developer mailing list