PyQt5 + Python 3.5.1: QProgressBar 似乎无法连接到信号

PyQt5 + Python 3.5.1: QProgressBar seems to not be able to connect to signals

这是我的代码:

#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtCore import pyqtSlot,pyqtSignal

class QutieBar(QProgressBar):
    value = 0

    @pyqtSlot()
    def increaseValue(progressBar):
        progressBar.setValue(progressBar.value)
        progressBar.value = progressBar.value+1

# Create an PyQT4 application object.
a = QApplication(sys.argv)       

# The QWidget widget is the base class of all user interface objects in PyQt4.
w = QWidget()

# Set window size. 
w.resize(320, 240)

# Set window title  
w.setWindowTitle("Progressbar") 

# Create progressBar. 
bar = QutieBar(w)
bar.resize(320,50)    
bar.setValue(0)
bar.move(0,20)

# create timer for progressBar
timer = QTimer()
bar.connect(timer, SIGNAL("timeout()"), bar, SLOT("increaseValue()"))
timer.start(400) 

# Show window
w.show() 

sys.exit(a.exec_())

这是它吐出的错误:

C:\Users\Pixie\Development\New folder>test6 Traceback (most recent call last): File "C:\Users\Pixie\Development\New folder\test6.py", line 38, in bar.connect(timer, SIGNAL("timeout()"), bar, SLOT("increaseValue()")) AttributeError: 'QutieBar' object has no attribute 'connect'

我完全不知道发生了什么。根据我的广泛搜索,这个 似乎 已正确连接,但由于某些明显的原因,PyQt5 很时髦。

您正在使用 bar.connect(timer, SIGNAL("timeout()"), bar, SLOT("increaseValue()")),这是 PyQt4 中的旧信号槽语法。

您应该按照 the PyQt5 documentation 使用 timer.timeout.connect(bar.increaseValue)