Is there a way to add a new field column to a vectorlayer's features in qfield's plugin?

Basically, I want to add a new field in a loaded project’s layer and the features in it.

I’ve found out that in QGIS’s QgsFields class, an “append” function is supported, but unfortunately it is not a QML callable function although the QgsFields class is registered as a meta type by qfield in its plugin system.

Is now there in qfield v3.5.0 any way to realize it?

Or if it is not possible now in v3.5.0, will there be a new API in qfield’s FeatureUtils singleton for wrapping this QgsFields::append() function to expose this capability for in-plugin usage in the future?

Thanks for any discussion and reply in advance.


Imported from GitHub discussion by @gitpydev on 2025-03-01T07:55:18Z

gitpydev , greetings – it is not possible ATM to modify (i.e. rename/add/remove) vector layers’ fields. We could make relevant QgsVectorLayer functions Q_INOKABLE to achieve that if needed.


Imported from GitHub comment by @nirvn on 2025-03-08T10:58:34Z

Hi!

Now that QField includes the ability to create projects from scratch, it would be very useful to have some QgsVectorLayer functions exposed as Q_INVOKABLE, in particular addAttribute.

I’ve been experimenting with a “NewAttribute” plugin, but without addAttribute being accessible I haven’t been able to make it work.

Would it be possible to expose this function as Q_INVOKABLE? That would be a great help!

Thanks a lot for considering this.

This will be available in the next version of QField, which will be released by the end of the year.

1 Like