Below, I show you an extract of the code to load a layer using threads, following the instructions shown here: Snorfalorpagus But the layer does not load, or it loads but it is not shown, and the truth is that I have no idea why this happens
class Worker(QtCore.QObject): def __init__(self): QtCore.QObject.__init__(self) def run(self): path = "C:\Users\user\Documents" layer = QgsVectorLayer(path, "Layer.shp", "ogr") QgsMapLayerRegistry.instance().addMapLayer(layer) ...
Edit copied in by mod from answer response:
- Yes, a cut/paste error was here, but don't in PY file,sorry.
- yes, I tested that layer is valid with method 'layer.isValid()' and return True, for this, I supposse that layer is loaded, but I don't know, why it Don't show in Layer Panel.
and the MainClass with call and run the worked class is..
class MainClass: """QGIS Plugin Implementation."""
def __init__(self, iface): ... def run(self): """Run method that performs all the real work""" # show the dialog self.dlg.show() # Run the dialog event loop result = self.dlg.exec_() # See if OK was pressed if result: # Do something useful here - delete the line containing pass and # substitute with your code. # start the Worker in a new thread thread = QtCore.QThread(self.iface) worker = Worker(arg) worker.moveToThread(thread) worker.finished.connect(self.workerFinished) worker.error.connect(self.workerError) worker.progress.connect(progressBar.setValue) thread.started.connect(worker.run) thread.start() self.thread = thread self.worker = worker
And Sorry for my english.