title: PyQt5 How to make updating progress bar when line from text is reading?
body: <p>I'm a beginner in Python and PyQt. I want to do simple UI - click button opens file dialog, next choose text file and it's adding to list line by line. And this part works fine. When file has about 500k lines adding takes some time, so decided to make a progress bar. I was searching how to do this and here is my code:</p>
  <pre><code>SIZE = 0
  VALUE = 0
  
  class External(QThread):
          countChanged = pyqtSignal(int)
          def run(self):
                  while VALUE &lt;= SIZE:
                  counter = (VALUE*100/SIZE)
                  time.sleep(1)
                  self.countChanged.emit(int(counter))
  
  class Ui_MainWindow(object):
          def setupUi(self, MainWindow):
                  \... some UI setup ...\
                  self.listView = QtWidgets.QListWidget()
                  self.pushButton = QtWidgets.QPushButton()
                  self.pushButton.clicked.connect(self.openFile)
                  self.progressBar = QtWidgets.QProgressBar()
          
          def openFile(self):
                  global SIZE
                  global VALUE
                  openfile = QFileDialog.getOpenFileName(self.pushButton, &quot;Open File&quot;, &quot;&quot;, &quot;TXT (*.txt)&quot;)
                  SIZE = os.stat(openfile[0]).st_size
                  if not openfile[0] == &quot;&quot;:
                          with open(openfile[0], 'r') as f:
                                  file_text = f.readlines()
                                  self.calc = External()
                                  self.calc.countChanged.connect(self.onCountChanged)
                                  self.calc.start()
                          for line in file_text:
                                  self.listView.addItem(line)
                                  VALUE = VALUE + sys.getsizeof(line)
  
          def onCountChanged(self, counter):
                  self.progressBar.setValue(counter)
  </code></pre>
  <p>Text is added to list properly each time. The progress bar sometimes doesn't load at all, sometimes loads up to several percent (e.g. 23%), but doesn't show real-time progress, it looks as the progress value was added after loading the entire list.</p>
  <p><strong>1)</strong> Not sure if I can use getsizeof() to check how much data has already been processed - What should I use instead?</p>
  <p><strong>2)</strong> Why my progress bar doesn't work properly? What the code should look like?</p>
  <p>Thank you for your interest.</p>