2

In a QGIS layers attribute form configuration I have the following Python Init Code Configuration:

enter image description here

Code in plain text:

# -*- coding: utf-8 -*-

from qgis.PyQt.QtWidgets import QWidget, QLineEdit
from qgis.PyQt.QtCore import Qt

def atlas_punkte_init_values(dialog, layer, feature):
    #geom = feature.geometry()
    control = dialog.findChild(QLineEdit, 'str')
    print(control)
    l = dialog.findChildren(QLabel)
    print(l)

As one can see at first sight, this code is erroneous, because QLabel is not imported. By means of this, I would expect an exception somewhat like ...NameError: name 'QLabel' is not defined, but the only thing I get is this:

enter image description here

Because far trickier error constellations are imaginable than a forgotten import, debugging of more extensive scripts is nearly impossible that way.

First idea is to look at python errors in the log or the python console, but thats a fail.

Do I miss a location where qualified exceptions are thrown by these scripts or is there really no chance to properly debug these?

2

You should allow macros to run in "Settings > General". QGIS cannot find the function because macros is not allowed. In this case, QGIS shows an error message dialog and gives a warning in Log Messages panel in later versions as in the image.

enter image description here

When using 'Python Init Code Configuration', debugging is a black hole in earlier QGIS 3 versions. But in QGIS v3.12+, "Python error" window shows the error message now.

enter image description here

| improve this answer | |

Your Answer

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

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