Thursday, 15 September 2016

qgis plugins - Canceling task currently running in background using PyQGis?


I am trying to close QgsProject on loading layer (if password and username from QgSProject - datasource are incorrect) before QgsCredentialDialog is shown.


on signal :




QgsProject.instance().loadingLayer.connect(self.load_log)





  • If password and user are correct -> pass




  • if password and user are not correct: close the project





I am using :


    project = QgsProject.instance()
project.clear()

but QgsCredentialDialog still shows up.


enter image description here


after clear project if I use :



iface.actionExit().trigger()




This shows up:


enter image description here


If I click yes, QgsCredentialDialog is shown again


How do I close the project and everything connected with that project (signals,actions,tasks,connections,...)?


NOTE:


QgsTaskManager().cancelAll() # NOT WORKING
tasks = QgsApplication.taskManager().activeTasks()
for task in tasks:
print (task.canCancel()) # False

print (task.description()) # Loading “C:/Users/User/Desktop/some_project.qgs”
print (task.flags()) #

task.cancel() # NOT WORKING

Since task.canCancel() is FALSE (I think that is main problem here), is it possible to change task.canCancel() into TRUE?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...