[Qgis-developer] segmentation fault in plugin using zoom tool

Radim Blazek radim.blazek at gmail.com
Thu Oct 5 05:07:37 EDT 2006


On 10/5/06, Martin Dobias <wonder.sk at gmail.com> wrote:
> On 10/5/06, nitin quick <quick.nitin at gmail.com> wrote:
> > greetings developers,
> > i am currently coding a plugin which will make use of map tools but it
> > is giving me seg fault.
> > Operation is such : plugin has a pointer to qgsmaptoolzoom, on
> > activating action for this plugin it do
> >
> > PointTool::PointTool(QgisApp * theQGisApp,
> >                                        QgisIface * theQgisInterface):
> >                  QgisPlugin(sName,sDescription,sPluginVersion,sPluginType),
> >                  mQGisApp(theQGisApp),
> >                  mQGisIface(theQgisInterface)
> > {
> >         zoomTool=new QgsMapToolZoom(mQGisIface->getMapCanvas(),false);
> > }
> >
> > void PointTool::okReceived()
> > {
> >         mQGisIface->getMapCanvas()->setMapTool(zoomTool);
> >
> > }
> > this will make zoomTool current map tool.
> > Aftert this if i select tool identifyfeature, and again select
> > zoomTool from plugin menu it results in segmentation fault. I couldn't
> > find solution for this problem. please help me get out of it. The code
> > which i put up is i think only relevant here, rest is std generated by
> > plugin builder or i can put whole code.
> > quickNitin
>
> Hi,
>
> if I recall correctly, you shouldn't store map tool because the tool
> is owned by map canvas and the old tool gets always deleted in
> QgsMapCanvas::setMapTool. So your code should look like
>
> void PointTool::okReceived()
> {
>         QgsMapCanvas* canvas = mQGisIface->getMapCanvas();
>         canvas->setMapTool(new QgsMapToolZoom(canvas,false));
> }

Note that I added also
QgsMapCanvas::unsetMapTool(QgsMapTool* mapTool)
to delete current tool if it matches the passed one
(or the last non zoom) e.g. when tool has to be stopped from plugin.
Maybe a better solution exists?  Note that the current tool
(last non-zoom) can only be deleted if it is that set previously
by plugin.

Radim

> Hope that helps,
> Martin
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.qgis.org
> http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
>



More information about the Qgis-developer mailing list