0

I'm trying to debug a pyQGIS plugin, but can't get one of the Qthread working. I was told QgsMessageLog was the best way;

QgsMessageLog.logMessage("before simplify", "plugin", level=Qgis.Info)

At best I get "NameError: name 'Qgis' is not defined", or nothing if I remove the last 1-2 arguments.

from qgis.core import QgsMessageLog

from PyQt5.QtCore import QObject

QGIS 3.2 on Win10 Pro...

1 Answer 1

2

You need to import Qgis.

from qgis.core import Qgis, QgsMessageLog
QgsMessageLog.logMessage("before simplify", "plugin", level=Qgis.Info)
4
  • Of course... that said it still doesn't display anything. At least no error message, but even with a warning level, nada. And by now I just figured out that I just have to remove the Qthread to find the errors in 5 minutes, instead of spending hours trying to debug it without any indication...
    – S.E.
    Jun 2, 2022 at 20:31
  • QgsMessageLog adds a message in the QGIS logs, the small comic strip bubble in the right bottom corner.
    – etrimaille
    Jun 3, 2022 at 8:27
  • Right, and usually the message automatically appears above the map, at least with my installation. Here nothing, even if I click on the bubble icon. And no exceptions/traceback... Apparently a problem with Qthread, I can only run smaller datasets with Qthread, it just freezes or crashes QGIS (faster than the same class/functions/code/data without it). Qthread also seems unstable, the same data set works one time, then the next day it crashes. Thanks anyway!
    – S.E.
    Jun 3, 2022 at 22:00
  • 2
    I'm not sure what is your script. Instead of QThread, maybe use QgsTask and QgsTask.fromFunction ? Also, why are you on QGIS 3.2 ? or is it a typo 3.20 ?
    – etrimaille
    Jun 4, 2022 at 8:57

Your Answer

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

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