P.R.
P.R.

Reputation: 3917

How to add a function to the Qt Mainloop

Is there an easy way in Qt to add a function to the standard Qt mainloop (exec())? Ideally something like how it would be done in GTK:

import gobject
gobject.timeout_add(milliseconds, callback)

I need this for a simple GUI which just grabs and displays a video feed from a camera.

Upvotes: 2

Views: 792

Answers (1)

Pavel Strakhov
Pavel Strakhov

Reputation: 40512

Use QTimer:

timer = QTimer()
timer.timeout.connect(callback)
timer.start(msecs)

For single-shot timeouts, you can use the singleShot class method directly:

QTimer.singleShot(msecs, callback);

Upvotes: 5

Related Questions