3

I am trying to port my old QGIS 2.x processing scripts to QGIS 3.x. One of my scripts just needs two variables to initiate several processes to set-up a working environment in my QGIS map document (downloading layers, subsetting data, etc). Using the template script (QGIS 3.2.0) I have changed the static variables, 'INPUT' and 'OUTPUT' to 'START' and 'END'. I then changed the initAlogrithm function to:

    def initAlgorithm(self, config=None):
    """
    Here we define the inputs and output of the algorithm, along
    with some other properties.
    """

    self.addParameter(
        QgsProcessingParameterString(
            self.START,
            self.tr('Model Start Time'),
            'YYYYMMDDHH'
        )
    )

    self.addParameter(
        QgsProcessingParameterString(
            self.END,
            self.tr('Model End Time'),
            'YYYYMMDDHH'
        )
    )

Then in the processAlgorithm() function, I tried calling the inputs as:

start_time = self.parameterAsString(
        parameters,
        self.START,
        context)

This yields the following error:

TypeError: invalid result from AssimStartUp.processAlgorithm(), NoneType cannot be converted to a C/C++ QMap<QString,QVariant> in this context

So, what am I doing wrong that is prohibiting the string from the input window being passed into the processAlgorithm() function?

1 Answer 1

7

The error is caused because your processAlgorithm implementation isn't returning any values. If a python function has no return ... statement, it's treated as returning a None value, yet processAlgorithm must return a dictionary of results. Hence the error:

TypeError: invalid result from AssimStartUp.processAlgorithm(), NoneType cannot be converted to a C/C++ QMap<QString,QVariant> in this context

The easiest way to fix this is to ensure that your processingAlgorithm implementation ends with a return statement, e.g. return {}. But the correct approach is to ensure that this returned dictionary is populated with all the results of your algorithm, for instance paths to created layers, values for numeric outputs, etc. What to include would depend entirely on the logic of your particular algorithm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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