I’m using Qt on top of a game and I need to call an update function regularly. I once did this by having a QTimer, with 0 in interval, calling an update function similar to what you see below.
class Window : public QMainWindow
{
Q_OBJECT
private:
QTimer timer;
public:
Window()
{
timer.setInterval(0);
timer.start();
connect(&timer, SIGNAL(timeout()), this, SLOT(update()));
}
public slots:
void update()
{
// Update game logic
}
};
I don’t remember the exact Qt version I used, but this used to work without any problems.
However, in Qt 4.8.4 and Qt 5, the window “freezes”, probably due to QTimer receiving all execution time without the GUI updating in between.
Does anyone know how to solve this?
↧