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

Martin Dobias wonder.sk at gmail.com
Thu Oct 5 04:29:18 EDT 2006


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));
}

Hope that helps,
Martin



More information about the Qgis-developer mailing list