So I am currently working on a QGIS Python plugin and I want to update a QDialog with textoutput while an import of data from one file the another is running.

So while it is grabbing data from one file and inserting it into the other I want my output in the dialog too look like:

Importing WMS: connection-wms/example/url: abc.com...
Importing WMS: connection-wms/example2/url: abc.com...
Importing WFS: connection-wms/example3/url: abc.com...

and so on...

My problem is that when I call exec_() on the dialog everything else freezes, like it is waiting for the dialog to do something. When I close the dialog the import runs as intended.

I have allready tried QCoreApplication.processEvents() but somehow can not get it to work.

My current attempt is to run the dialog in its own thread, but with Thread from the threading lib this does not seem to work.

Here is the logic of the import action:

class DatasourceDistributor:

def importSources(self):
    self.dialog = ProgressLog()

    self.dictionaryOfCheckedSources = {**self.dictionaryOfCheckedDataBaseSources,

    if self.dictionaryOfCheckedSources:

        targetParser = configparser.ConfigParser()
        targetParser.optionxform = str

        for key in self.dictionaryOfCheckedSources:
            iterator = 0

            if key in self.availableWebSources:
                if self.parser.has_section('qgis'):
                    for element in range(len(self.dictionaryOfCheckedWebSources[key])):
                        self.importWebSources(iterator, key, targetParser)
                        iterator += 1
                for element in range(len(self.dictionaryOfCheckedDataBaseSources[key])):
                    self.importDBSources(iterator, key, targetParser)
                    iterator += 1

        with open(self.targetQgisIniFile, 'w') as qgisconf:


I feed the dialog with text in another for loop in self.importWebSources(iterator, key, targetParser)

And here the dialog class:

class ProgressLog(QDialog):

def __init__(self, *args, **kwargs):
    super(ProgressLog, self).__init__(*args, **kwargs)

    self.setWindowTitle("Importing Datasources...")
    self.layout = QVBoxLayout()
    self.progesslog = QTextBrowser()

Please keep in mind that this is my first contact with Qgis Plugins and also with Python


  • 1
    Just a small thought...what happens if you call self.dialog.show() instead of .exec_()? – Ben W May 7 '20 at 7:40
  • well dam, on first sight that seems to work, but I have to check if it updates live, with the current data the whole output is just instantly there. Thank you tho!! – brezz0r May 7 '20 at 9:47

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.