4

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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jun 25, 2018 at 20:29

1 Answer 1

9

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.

answered Jun 26, 2018 at 2:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.