2

I have this PySide app and I want to run the function pp every 1 second, but when I run the app it only ran for 1 time.

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())

The console outputs:

LOL
True

I searched in the Qt documentation but found nothing

eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

3

Your connection is wrong. Change self.timer.timeout.connect(self.pp()) to self.timer.timeout.connect(self.pp), because you want to connect to the function, not its output.

Passerby
  • 808
  • 1
  • 5
  • 9