May 2019
Intermediate to advanced
542 pages
13h 37m
English
Although the moveToThread() method of working with QThread is the preferred approach recommended by the documentation, there is another way that works perfectly well and, in some way, simplifies our code. This approach is to create our Worker class by subclassing QThread and overriding the run() method using our worker code.
For example, create a copy of SlowSearcher and alter it as follows:
class SlowSearcherThread(qtc.QThread): # rename "do_search()" to "run()": def run (self): root = qtc.QDir.rootPath() self._search(self.term, root) self.finished.emit() # The rest of the class is the same
Here, we've altered only three things:
Read now
Unlock full access