When using python pyqt, I made a Qprogressbar with an updating the number using Q thread. The code shown below is successful in first time, howerver it will crash with doing another run.
This is for Python PyQt5, in Python 3.5 system. And I have try reset the progressbar to 0 but it didn't seem right
This is the call function after I click the load file button, the load file button and progressbar is located the in QtWidgets.Qmainwindows
loading_event_name = QtWidgets.QFileDialog.getOpenFileNames(self, 'CSV File', 'C:\\', '*.csv')
self.loading_progress_bar.reset()
self.loading_thread = QThread()
self.loading_worker = Load_Task_Thread()
self.loading_worker.moveToThread(self.loading_thread)
self.loading_thread.started.connect(self.loading_worker.run)
self.loading_thread.start()
self.loading_worker.Load_taskFinished.connect(self.Load_onFinished)
self.loading_worker.Loading_progressChanged.connect(self.loading_progress_bar.setValue, Qt.QueuedConnection)'''
The first load file thread will work perfectly, but the next click if I want to load new file, software will crash, thread is not updating,progressbar is not updating the number like the first time and keep in zero since I reset it. In debug mode I can not emit any number to the progressbar too:
class Load_Task_Thread(QThread):
Load_taskFinished = pyqtSignal()
Loading_progressChanged = pyqtSignal(int)
def run(self):
progress = 0
for file_name_num in range(len(loading_event[0])):
progress = 90 * file_name_num/len(loading_event_name[0])
self.Loading_progressChanged.emit(progress)
1+1.....
self.Loading_progressChanged.emit(100)
self.Load_taskFinished.emit()
I expected that no matter how many clicks for selecting the new file, the progress bar can be updated. Or is there any other easy way that can show a progressbar to show the process of loading.