1

For one plugin I maintain, I can't figure out how to return output layer when the user hits 'Cancel'. Basically I'm looping over a set of results in processAlgorithm which populates the output layer and I'd expect to have the output layer returned with all results calculated until 'Cancel' was clicked.

A minimal example:

def processAlgorithm(self, parameters, context, feedback):
    (sink, self.dest_id) = self.parameterAsSink(parameters, 'Output', context,
                                                list_of_fields,
                                                QgsWkbTypes.Polygon,
                                                CRS)

    for result in results:
        if feedback.isCanceled():
            break

        # Do smth smart

        sink.addFeature(result)

    return {'Output': self.dest_id}

However, no layer is added to the map when 'Cancel' is hit mid-way through processing.

EDIT Just to clarify, I'd have expected that if feedback.isCanceled(): break would yield return {'Output': self.dest_id}, i.e. the output layer with the added features until feedback.isCanceled() is called.

bumped to the homepage by Community 4 mins ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

0

Asked the same question on the QGIS dev mailing list and according to @nyalldawson this is intended behavior, so as not to receive misleading partial results.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.