[QGIS-trac] Re: [Quantum GIS] #2006: Python: cannot connect SIGNAL canvasClicked with a function

Quantum GIS qgis at qgis.org
Tue Oct 13 11:07:12 EDT 2009


#2006: Python: cannot connect SIGNAL canvasClicked with a function
--------------------------------------------------------------+-------------
        Reporter:  trapanator                                 |         Owner:  borysiasty   
            Type:  bug                                        |        Status:  closed       
        Priority:  critical: causes crash or data corruption  |     Milestone:  Version 1.4.0
       Component:  Python plugins and bindings                |       Version:  HEAD         
      Resolution:  invalid                                    |      Keywords:               
Platform_version:  1.3.0                                      |      Platform:  Windows      
        Must_fix:  Yes                                        |   Status_info:  0            
--------------------------------------------------------------+-------------
Changes (by jef):

  * status:  new => closed
  * resolution:  => invalid

Comment:

 the latter works.  The problem is that your tool is destroyed before you
 get a chance to use it.  Following works:

 {{{
 # Import the PyQt and QGIS libraries
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 from qgis.core import *
 from qgis.gui import *

 class simplePlugin:

         def __init__(self, iface):
                 # Save reference to the QGIS interface
                 self.iface = iface

         def initGui(self):
                 # Create action that will start plugin configuration
                 self.action = QAction(QIcon(":/plugins/totem/icon.png"),
 "test", self.iface.mainWindow())
                 # connect the action to the run method
                 QObject.connect(self.action, SIGNAL("activated()"),
 self.run)
                 self.iface.addPluginToMenu("Plugin...", self.action)

         def unload(self):
                 # Remove the plugin menu item and icon
                 self.iface.removePluginMenu("Plugin...", self.action)
                 self.iface.removeToolBarIcon(self.action)

         def run(self):
                 mapCanvas=self.iface.mapCanvas()
                 # Create the appropriate map tool and connect the
 gotPoint() signal.
                 self.emitPoint = QgsMapToolEmitPoint(mapCanvas)
                 mapCanvas.setMapTool(self.emitPoint)
                 QObject.connect(self.emitPoint,
 SIGNAL("canvasClicked(const QgsPoint &, Qt::MouseButton)"),
 self.clickButton)

         def clickButton(self, pnt, but):
                 QMessageBox.information(None, "Nome finestra", "cliccato",
 "&Ok", "&Cancel",  "", 0, 1)
 }}}

-- 
Ticket URL: <http://trac.osgeo.org/qgis/ticket/2006#comment:1>
Quantum GIS <http://qgis.org>
Quantum GIS is an Open Source GIS viewer/editor supporting OGR, PostGIS, and GRASS formats


More information about the QGIS-trac mailing list