Clarification on Signal Exposure in QField Plugins

Hi,

I’ve been working on QField plugin and recently started exploring the use of signals. If I understand correctly, signals from QGIS classes can be accessed in QML when the class is exposed. For example, I’ve successfully connected to signals from QgsVectorLayer like featureAdded and geometryChanged in QML using the following:

property var my_layer: qgisProject.mapLayersByName("my_layer")[0]

Connections {
    target: my_layer

    onGeometryChanged: {
        iface.logMessage("onGeometryChanged")
    }
    onFeatureAdded: {
        iface.logMessage("onFeatureAdded")
    }
}

This works perfectly, but I’m trying to understand how to confirm whether signals for a specific class are fully exposed to QML or if there’s a custom mechanism in QField that bridges these signals.

From my understanding, QgsVectorLayer is exposed to QML with :

qmlRegisterType<QgsVectorLayer>( "org.qgis", 1, 0, "VectorLayer")

Does this mean that all QgsVectorLayer signals (like featureAdded, geometryChanged, committedFeaturesAdded, etc.) are automatically available in QML?

I’ve reviewed files like layerobserver.cpp and featurelistmodel.cpp, which appear to connect QgsVectorLayer signals internally. However, in the plugin I use target:my_layer (a QgsVectorLayer instance) and not to something like layerObserver.

I’d appreciate it if you could clarify:

  • Are all QgsVectorLayer signals exposed to QML by default, or is there a custom mechanism in QField for signal exposure?
  • If not all signals are exposed, are there specific parts of the codebase I can refer to confirm which signals are available for a given class in QField?

Apologies if my question isn’t clear—I’m still learning about Plugin development with Qfield.

Thank you in advance !


Imported from GitHub discussion by @paul-carteron on 2024-12-13T10:54:55Z

paul-carteron , every Q_OBJECT or Q_GADGET class exposed in our QML environment (see QField/src/core/qgismobileapp.cpp at master · opengisch/QField · GitHub to see a list of those objects and gadgets exposed) will have their signals exposed to our QML environment.

It is possible a signal containing parameter types that are not exposed in the QML environment will be skipped. It’s not something I’ve tested before, but I can see a disabling logic there :slight_smile:


Imported from GitHub comment by @nirvn on 2024-12-14T08:33:44Z

Oh I see ! By default all signals are implemented. It’s just a matter of understanding exactly how a signal is triggered, and checking that the parameters are available in qfield.

I will continue exploring !

Thank you so much for your work and time :slight_smile:


Imported from GitHub comment by @paul-carteron on 2024-12-16T09:40:52Z