1
  1. 它第一次起作用,但在重新调用循环处理数据的函数时不再起作用。我有 2 个 python 程序。主要显示进度条,第二个循环围绕处理数据。我已经研究了整个 stackoverflow 和谷歌,并努力寻找解决方案。最接近的解决方案是“QProgressBar 完成加载 2 后出现无法解释的延迟”的问题,但我无法将其应用于我的问题。我也尝试应用 QApplication.processEvents() 但我没有成功。

    主程序……等等……

    def connectDevice(self)
      if self.usb_serial != None:
        self.ui.ProgressBar.setMinimum(0)  # settings for showing pyqt4 progress bar            
        self.ui.ProgressBar.setMaximum(0)  # not indicating as expected          
        self.ui.ProgressBar.setValue(0)    # first showing 0%
        self.device = ScopeDev(self.usb_serial)   # device.py my second Python program
        self.device.start()                       # Connect Call... class ScopeDev/def run(self):
        self.device.init_received.connect(self.init_received)     # end of data processing signal received
      else:
        self.Display_MSG("Connection Error", "device not plug into USB port." )
    
    def reprocessdata(self):
      logging.info("Re-Processing Data...")
      self.ui.ProgressBar.setMaximum(0)     # hoping to kick off the progress bar again. Not even showing 0% 
      self.ui.ProgressBar.setValue(0)       # I tried insert QApplication.processEvents() here but did not work
      self.device.init()                    # Call class ScopeDev/def init(self): data was being processed
    
    def init_received(self):
      logging.debug("Init received")
      self.ui.ProgressBar.setMaximum(1)         # indicated 100% on both times, when data processing completed
      self.ui.ProgressBar.setValue(1)           # first from connectDevice and second time from reprocessdata
    
  2. 我的第二个python程序......等等......

    class ScopeDev (QtCore.QThread):
      init_received = QtCore.pyqtSignal()
    
    def __init__(self, usb_serial, usb_serial_baud=9600, timeout=2):
      QtCore.QThread.__init__(self, None)
      self.serial = serial.Serial(usb_serial, usb_serial_baud, timeout=timeout)   # connect to Arduino
      logging.debug("Connected (%s)" % usb_serial)
    
    def run(self):
      self.init()                    #1 Call...def init(self):
    
    def init(self):
      self.serial.readline().rstrip()            # read println put out by Arduino/plaser.ino
      self.serial.write(b'init')                    
      self.sread(expect=b'^done_init$')
    
    def sread(self, expect=b'^cmd$'):   # loops around to process data from Arduino...etc. when completed...
      self.init_received.emit()       # emits the outbound signal back to the main
    
4

1 回答 1

0

这里有一些建议:

首先删除第一个初始化,这 3 行:

self.ui.ProgressBar.setMinimum(0)  # settings for showing pyqt4 progress bar            
self.ui.ProgressBar.setMaximum(0)  # not indicating as expected          
self.ui.ProgressBar.setValue(0)    # first showing 0%

这是默认完成的。

第二件事:reprocessdata尝试切换这两行:

  self.ui.ProgressBar.setMaximum(0)        
  self.ui.ProgressBar.setValue(0)

3.代替前两行,尝试重置进度条:

void QProgressBar::reset () [插槽]

重置进度条。进度条“倒带”并且没有显示任何进度。

在你的情况下:self.ui.ProgressBar.reset()

-我不明白你为什么使用进度条?因为你只有两个状态 - 0 (0%) 和 1 (100%)

于 2013-09-12T14:24:26.490 回答