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):

def run(self):
    path = "C:\Users\user\Documents"
    layer = QgsVectorLayer(path, "Layer.shp", "ogr")

Edit copied in by mod from answer response:

  1. Yes, a cut/paste error was here, but don't in PY file,sorry.
  2. 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.
  3. 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
        # 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)           
            self.thread = thread
            self.worker = worker 

And Sorry for my english.

  • 1. Your python indentation is wrong, is that just a cut/paste here problem? 2. Have you tested that layer is valid after the call to QgsVectorLayer? 3. How have you called this class and its run method? – Spacedman Feb 10 '17 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.