<div dir="ltr"><div dir="ltr">Hello,<br><br>I am trying to add a layer to project in a QgsProcessingAlgorithm.<br><br>I run the folowing test code, just to find a way to add a layer to the project. I don't want to use featureSink because at the end the layer I want to add is a raster layer :<br><br><div>def processAlgorithm(self, parameters, context, feedback):</div><div>        """</div><div>        Here is where the processing itself takes place.</div><div>        """</div><div><br></div><div>        vlayer1 = QgsVectorLayer('Point?crs=epsg:4326&field=id:integer&field=name:string(20)&index=yes', 'vlayer1', "memory")</div><div>        vlayer2 = QgsVectorLayer('Point?crs=epsg:4326&field=id:integer&field=name:string(20)&index=yes', 'vlayer2', "memory")</div><div>        vlayer3 = QgsVectorLayer('Point?crs=epsg:4326&field=id:integer&field=name:string(20)&index=yes', 'vlayer3', "memory")</div><div>        vlayer4 = QgsVectorLayer('Point?crs=epsg:4326&field=id:integer&field=name:string(20)&index=yes', 'vlayer4', "memory")</div><div><br></div><div>        context.addLayerToLoadOnCompletion(<a href="http://vlayer1.id">vlayer1.id</a>(),context.LayerDetails('toto', QgsProject.instance(), 'test1'))</div><div>        context.addLayerToLoadOnCompletion(<a href="http://vlayer2.id">vlayer2.id</a>(),context.LayerDetails('toto', context.project(), 'test2'))</div><div>        QgsProject.instance().addMapLayer(vlayer3, True)</div><div>        context.project().addMapLayer(vlayer4, True)</div><div><br></div><div>        </div><div>        return {self.OUTPUT: 'toto'}</div><div dir="ltr"><br></div><div>I read that adding a layer directly from instance() should not be used in a processing algorithm.</div>However, none of the created vectorLayer is added to the legend.</div><div dir="ltr"><br>I get a warning on processing feedback with no details in message log :<br>Chargement des couches de résultat<br>Les couches suivantes n'ont pas été générées correctement.<ul><li>vlayer1_98306459_f1bc_4285_b8dc_660502e5cb47</li><li>vlayer2_040a7ea0_7a5f_4e02_bfd1_4ce311c60219</li></ul>Vous pouvez vérifier le Panel de messages du journal dans la fenêtre principale de QGIS pour trouver plus d'informations à propos de l'exécution de l'algorithme.<br><br>Am i doing wrong or is there something broken in procesing API?<br><br>Thanks  <br clear="all"><div><br></div><div>Valérian</div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"></div></div></div></div></div></div>