Bug report #2006
Python: cannot connect SIGNAL canvasClicked with a function
| Status: | Closed | ||
|---|---|---|---|
| Priority: | Low | ||
| Assignee: | |||
| Category: | Python plugins | ||
| Affected QGIS version: | Regression?: | No | |
| Operating System: | Windows | Easy fix?: | No |
| Pull Request or Patch supplied: | Resolution: | invalid | |
| Crashes QGIS or corrupts data: | Copied to github as #: | 12066 |
Description
I cannot connect SIGNAL canvasClicked anymore (QGIS 1.3.0)
this:
QObject.connect(emitPoint, QgsPoint &, Qt.MouseButton">SIGNAL"), self.clickButton)
doesn't work anymore.
Neither:
QObject.connect(emitPoint, QgsPoint &, Qt::MouseButton">SIGNAL"), self.clickButton)
attached a simple plugin.
History
#1
Updated by Jürgen Fischer about 16 years ago
- Resolution set to invalid
- Status changed from Open to 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 [[PyQt]]4.QtCore import *
from [[PyQt]]4.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)