I'm trying to get the "cancel" to work for my QgsTask, I have created a simple example to illustrate, When I press the "x" i want it to print reslut: None values: False, hence it just finishes without printing anything. If I let it finish (wait for 20 seconds) its prints reslut: None values: True Test QgsTask

import time
def test_task(task):
 for i in range(20):
  if task.isCanceled():
   return False
 return True

def end_method(reslut, values):
 print('reslut: {r} values: {v}'.format(r=reslut, v=values))

task = QgsTask.fromFunction('Test task', test_task, on_finished=end_method)


Any thoughts on what I shall use instead of task.isCanceled()? (I'm using QGIS3.2)


Your Answer

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

Browse other questions tagged or ask your own question.