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

on signal :


  • If password and user are correct -> pass

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

I am using :

    project = QgsProject.instance()

but QgsCredentialDialog still shows up.

enter image description here

after clear project if I use :


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,...)?


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()) # <qgis._core.QgsTask.Flags object at 0x000002330527E4C8>

    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?

  • 1
    If the tasks are contained in QgsTaskManager, you could try cancelling it using QgsTaskManager().cancelAll() before creating a new project. – Joseph Apr 11 '19 at 14:12
  • 1
    Unfortunately it does not work either :( If I click yes in dialog "Active Tasks" QgsCredentialDialog is shown again @Joseph – ncica Apr 11 '19 at 14:21
  • Duplicated gis.stackexchange.com/questions/318585/… – Fran Raga Apr 17 '19 at 12:18

Your Answer

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

Browse other questions tagged or ask your own question.