How to repeat a call of a function of every X seconds in PyQt?

4

I'm developing a small application in Pyqt4 where I need to load the data into a table coming from a Webservice. This I was able to do quietly. But now, I need to update this every 1 minute.

How can I do a repetition of a call to a function every X seconds in PyQt4?

Is there anything specific for this in Pyqt? (something like Javascript's setInterval)

Note : The process of reloading the data in this range must be asynchronous     

asked by anonymous 11.11.2016 / 12:14

1 answer

5

You can use%% of Qt . In the PyQt4 documentation I did not find any examples, but I believe it should look like this (every 1 second):

from PyQt4.QtCore import QTimer

def chamar():
    print 'Foo'

timer = QTimer()
timer.timeout.connect(chamar)
timer.start(1000)

I still think it's best to use QTimer , so if a function takes longer than the timeout there will be no chance of it being executed two or more simultaneously (which can cause conflicts and "crashes"), :

from PyQt4.QtCore import QTimer

def chamar():
    # Aqui fica o código que será executado

    timer = QTimer()
    timer.setSingleShot(True)
    timer.timeout.connect(chamar)
    timer.start(1000)

chamar()
    
11.11.2016 / 12:30