[QGIS-Developer] Dirtying project within model classes or not
David Koňařík
dvdkon at konarici.cz
Tue Nov 4 00:44:49 PST 2025
Hi all,
On 11/4/25 09:22, Julien Cabieces via QGIS-Developer wrote:
> Why not plain old callbacks instead of signals (I don't like that much
> signals, It's hard to debug, I think we use them too much). QgsSymbol could have some
> methods like this
>
> void addModifiedCallback( std::function<void> callback )
> {
> mCallbacks.append( callback );
> }
>
> void dirty()
> {
> for( auto callback : mCallbacks )
> callback();
> }
>
> void setSize( double size )
> {
> ...
> dirty();
> }
>
> And QgsFeatureRenderer would report it to QgsVectorLayer, which would
> then report it to QgsProject
I don't have an opinion on dirtying (due to lack of experience with it),
but I do have an opinion on signals and callbacks:
I agree that QGIS sometimes overuses signals, but I think callbacks are
only a reasonable replacement where there will be exactly one callback,
and only when that callback isn't stored in an object.
Apart from the code duplication introduced by manually handling lists of
callback functions (and slowly reimplementing signals ourselves),
signals, when attached to objects, will automatically respond to the
destruction of one of the endpoints. This means that properly-connected
signals will never cause use-after-free issues, and that is reason
enough to use them, in my opinion.
David Koňařík
More information about the QGIS-Developer
mailing list