Answer for anybody that would have the same question :
I found 2 ways to add a virtual field to an output (vector) layer from a model :
- Create a new process that edits the output layer of the model using the
vector_layer.addExpressionField()method ; this process should normally be run before the model terminates and releases its outputs so the virtual field should be present in the output file. Pros : you get a lot of control over the buildingexpression of the field and you can use inputs from the model (to name the field for example). - Add the virtual laye through a .qml style file using the Edit Rendering Style For Outputs menu ; the virtual field names and expression can be part of a .qml file, simply make sure the Fields section is checked when saving the style of an existing layer. Pros : no need to create a new process and you can modify all other sections of the style at the same time
If you do both things then the style applied by the .qml file will prevail, removing the virtual field that could have been added using the process so that the output layer perfectly satisfies the contents of the .QMLqml file.
Big thanks to Erik :)