I'm going to know how I can get layers full path in table of contents in QGIS3.4 when my QGIS is closed and it's running such as daemon?
Rememebr: my shapefiles are in some different folders.
This below is my code:
# If you are not inside a QGIS console you first need to import # qgis and PyQt classes you will use in this script as shown below: from qgis.core import * import os #This is is needed in the pyqgis console also from qgis.core import ( QgsVectorLayer ) QgsApplication.setPrefixPath("/usr", True) # Create a reference to the QgsApplication. Setting the # second argument to False disables the GUI. qgs = QgsApplication(, False) qgs.initQgis() layersName = # Get the project instance project = QgsProject.instance() project.read('/media/sigma/Data/PyQGIS/pyqgis_project/pyqgis_hydro.qgz') #print(project.fileName()) for Layers in QgsProject.instance().mapLayers().values(): layersName.append(Layers.name()) path_to_shape_layers_in_toc = for l in layersName: path_to_shape_layers_in_toc.append(os.path.join(QgsProject.instance().homePath(),l+".shp")) vlayer = QgsVectorLayer(path_to_shape_layers_in_toc,"Countour Layers","ogr") if not vlayer.isValid(): print("Layers not loaded!")
I expect exact path shown in properties window for each layers in TOC, but with this code I get only layers path loaded in TOC, not full path.