Qt progress bar not updating

21 Aug

You can pass pretty much anything you want, or you can simply leave it empty.

If you do decide to pass something the function that will be connected to the signal must be able to accept that argument.

QMessage Box.critical(self, "No subreddits", "You didn't enter any subreddits.", Qt Gui. Ok) return self.progress_Maximum(len(subreddit_list)) self.progress_Value(0) for top_post in self._get_top_from_subreddits(subreddit_list): self.list_Item(top_post) self.progress_Value(self.progress_bar.value() 1) def main(): app = Qt Gui.

QApplication(sys.argv) form = Threading Tutorial() form.show() app.exec_() if __name__ == '__main__': main() method to see whether the thread is still running in your code.

limit=1".format(subreddit) headers = request = urllib2. Request(url, headers=headers) response = urllib2.urlopen(request) data = json.load(response) top_post = data['data']['children'][0]['data'] return "'' by in ".format(**top_post) def run(self): for subreddit in self.subreddits: top_post = self._get_top_post(subreddit) self.sleep(2) objects which we can use.

It's pretty self explanatory and the way we'd use that is by first making a list of subreddit names to pass to the thread and then calling it from the main UI code like this: That's it.

The GUI code will be set up just like in the previous tutorial I wrote.

If you don't understand what some parts of it are doing check out that blog post before continuing.

qt progress bar not updating-76qt progress bar not updating-19qt progress bar not updating-83

file on Git Hub's gist here: https://gist.github.com/Nikola-K/19d0c2b94c26200888bc (the whole project will also be linked at the bottom) Since this part isn't the focus of the tutorial I will skip any exception checking etc and just assume that the response from reddit will be valid.

Note: This tutorial assumes you're at least familiar with the things mentioned in the previous "Getting started with Py Qt" tutorial, and that you have basic understanding of what threads are and how they work.

In this post I'll write a simple app that fetches top posts from few different subreddits (subsections of reddit.com) while following API rules of 1 request per 2 seconds to illustrate the issues you encounter if you try to do it all in one thread.

The full documentation of methods can be found here: Qt4/Most of the time you'll just be using these, which are all self explanatory: method the main part of the code stays the same.

Another small difference is that we'll pass a list of subreddits upon thread instantiation and then assign it to a instance variable which we'll use in the class get Posts Thread(QThread): def __init__(self, subreddits): QThread.__init__(self) self.subreddits = subreddits def __del__(self): self.wait() def _get_top_post(self, subreddit): url = "https://