1

I am developing a QGIS (QGIS 3.6) dockwidget plugin where the user creates a rectangle (boundingbox) on the canvas and the plugin sends the rectangles coordinates attached to a HTTP request to my FME Server.

There is the main class SmallworldDataExtractorDockWidget and another class RectangleMapTool. In SmallworldDataExtractorDockWidget the general plugin functionalities are defined, in RectangleMapTool I create a custom QgsMapTool for creating the boundingbox in the canvas.

The creation of the boundingbox itself works and the RectangleMapTool can print the rectangle extent.

Now I am struggling in accessing the extent in the main class SmallworldDataExtractorDockWidget, where I want to associate the extent to variables and display the extent coordinates in input fields.

Plugin UI

What I have tried:

First try: In class RectangleMaptool:

def canvasReleaseEvent(self, e):
        self.isEmittingPoint = False
        r = self.rectangle()
        if r is not None:
            print("Rectangle:", r.xMinimum(), r.yMinimum(), r.xMaximum(), r.yMaximum())
            SmallworldDataExtractorDockWidget().minx_input.setText(r.xMinimum())

Error: RuntimeError: wrapped C/C++ object of type QLineEdit has been deleted

Second try: In class RectangleMaptool:

def canvasReleaseEvent(self, e):
    self.isEmittingPoint = False
    r = self.rectangle()
    if r is not None:
        print("Rectangle:", r.xMinimum(), r.yMinimum(), r.xMaximum(), r.yMaximum())
        self.result = r

and in class SmallworldDataExtractorDockWidget

def __init__(self, parent=None):
        """Constructor."""
        super(SmallworldDataExtractorDockWidget, self).__init__(parent)
        #some code
        #some code
        #some code
        self.maptool = RectangleMapTool(iface.mapCanvas())
        self.maptool.canvasClicked.connect(self.temp_box)


def temp_box(self, r):
        print(self.maptool.result)

Without any output...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.