I'm trying to add layer in group on QGIS using those code:
qgis_groups = QgsProject.instance().layerTreeRoot()
path = QgsProject.instance().readPath("./")
operators_path = join(path, 'RSX')
operators_content = [item for item in os.listdir(operators_path) if isdir(join(operators_path, item))]
shp = qgis_groups.findGroup('SHP')
for item in operators_content:
shp_path = join(operators_path, item, 'SHP')
for shp_file in glob.glob(join(shp_path, '*.shp')):
layer_name = basename(shp_file).replace(".shp", "")
layer = QgsVectorLayer(shp_file, layer_name, "ogr")
shp.addLayer(layer)
the layers loaded on QGIS become None only the last layer is worked, So I tried to call addLayer outside for It worked but the previous layer become None again.
Then I tried with inserLayer(i, layer) but same problem.
Anyone has an idea about that?