In QGIS graphical modeler, is it possible to set and export .QML extension of an output layer (adding .qml to the others extensions .shp, .shx, .dbf, ..)?

1 Answer 1


I realise your question specifically notes shapefiles, but if you output to GeoPackage, you can use the Package layers algorithm.

Alternatively you could create a processing script that saves the layer style to a QML on the file system:

enter image description here

Here is is simple script that will take an input map layer and save its current symbology as defined in the map to a .qml style with the same path/basename as the input layers data source. Note it will only work with simple file system datasets, not web layers, layers from delimited text files or layers in a database format, like GeoPackage or FileGDB.

from qgis.processing import alg
from qgis.core import QgsProcessingException
from pathlib import Path

@alg(name="savestyle", label=alg.tr("Save Style"), group='examplescripts', group_label='Example scripts')
@alg.input(type=alg.MAPLAYER, name="INPUT_LAYER", label="Input Layer")
@alg.output(type=alg.FILE, name='OUTPUT_STYLE', label='Output style file')
def save_style(instance, parameters, context, feedback, inputs):
    """Save style file"""

        lyr = instance.parameterAsLayer(parameters, "INPUT_LAYER", context)
        path = Path(lyr.dataProvider().dataSourceUri())
        if not path.exists():  # not a filesystem path
            raise QgsProcessingException("The layer path does not exist on the filesystem")
        path = f"{path.parent/path.stem}.qml"
        return {'OUTPUT_STYLE': path}
    except Exception as err:
        raise QgsProcessingException(f"Unable to save style for layer {parameters['INPUT_LAYER']}:\n{err}")

This processing script can then be added to a model:

enter image description here

enter image description here

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.