【问题标题】:Problem with QTimer() function in PySide6 the function doesn't loop [duplicate]PySide6中QTimer()函数的问题该函数不循环[重复]
【发布时间】:2022-01-04 03:47:03
【问题描述】:

我有这个 PySide 应用程序,我想每 1 秒运行一次函数 pp,但是当我运行该应用程序时,它只运行了 1 次。

import sys
from PySide6.QtWidgets import QMainWindow, QApplication
from PySide6 import QTimer


class MainWindow(QMainWindow):
    def __init__(self):

        QMainWindow.__init__(self)
        ###
        self.timer = QTimer()
        self.timer.timeout.connect(self.pp())
        self.timer.start(1000)
        print(self.timer.isActive())

    def pp(self):
        print("LOL")


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    #app.show()
    sys.exit(app.exec())

控制台输出:

LOL
True

我在Qt documentation 中搜索但一无所获

【问题讨论】:

  • 错字:改成self.timer.timeout.connect(self.pp)

标签: python pyqt qtimer pyside6


【解决方案1】:

您的连接错误。将self.timer.timeout.connect(self.pp()) 更改为self.timer.timeout.connect(self.pp),因为您要连接到函数,而不是它的输出。

【讨论】:

  • 非常感谢,我完全错过了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-15
  • 1970-01-01
  • 2014-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多