I am working on a QGIS plugin. The plugin has a main class running all the operations. I was trying to add a progress window in it. The window should load when a button is clicked running a method called "process" of same class at the back. I realized that for this I might need to use multi-threading.
Now I made changes by sending the process method to another thread. Everything works fine, except that the layer I was rendering from the the class of process method just stops working. It feels like everything has lost its connectivity. Even when I turn the layer off map canvas still keeps showing it in QGIS.
I also get this warning:
Warning: QObject::setParent: Cannot set parent, new parent is in a different thread
Can anybody tell me what the issue could be?
QgsTaskorQThread. My guess is you are trying to load a layer from the background thread. Please see the bold warning here: https://docs.qgis.org/3.22/en/docs/pyqgis_developer_cookbook/tasks.html#introduction about unsafe thread operations fromQgsTask. The same goes forQThread. If your thread class produces a layer, you can usepyqtsignalto emit the layer object and load it from the main thread. – Ben W May 05 '22 at 05:23