Opened 15 years ago
Closed 15 years ago
#2006 closed bug (invalid)
Python: cannot connect SIGNAL canvasClicked with a function
Reported by: | trapanator | Owned by: | borysiasty |
---|---|---|---|
Priority: | critical: causes crash or data corruption | Milestone: | Version 1.4.0 |
Component: | Python plugins and bindings | Version: | Trunk |
Keywords: | Cc: | ||
Must Fix for Release: | Yes | Platform: | Windows |
Platform Version: | 1.3.0 | Awaiting user input: | no |
Description
I cannot connect SIGNAL canvasClicked anymore (QGIS 1.3.0)
this:
QObject.connect(emitPoint, SIGNAL("canvasClicked( const QgsPoint &, Qt.MouseButton)"), self.clickButton)
doesn't work anymore.
Neither:
QObject.connect(emitPoint, SIGNAL("canvasClicked( const QgsPoint &, Qt::MouseButton)"), self.clickButton)
attached a simple plugin.
Attachments (1)
Change History (2)
by , 15 years ago
Attachment: | simple_plugin.zip added |
---|
comment:1 by , 15 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
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)
Note:
See TracTickets
for help on using tickets.
simple plugin