code: def connect_layer_listener(self):
          
          project = QgsProject.instance()
          project.layersWillBeRemoved.connect(self.get_layers)
          project.layersAdded.connect(self.get_layers)
          project.layersRemoved.connect(self.get_layers)
  
          self.iface.mapCanvas().layersChanged.connect(self.get_layers)
          self.iface.currentLayerChanged.connect(self.layer_changed)
docs: Establish a signal/slot to listen for layers loaded in QGIS.
  
          ..seealso:: disconnect_layer_listener