I am making a game with Qt and I am creating a custom game loop so that I can precisely control the logical timing and rendering with the maximum frame rate.
Typically, to create QWindow, you will do the following:
...
QGuiApplication app(argc,argv);
QWindow* window = new QWindow();
window.show();
app.exec();
...
And exec()will return when the window is closed.
However, I do it as follows:
QGuiApplication *app = new QGuiApplication(argc,argv);
QWindow* window = new QWindow();
window.show();
while (!terminate_loop) {
app->processEvents();
GameUpdate();
GameRender();
}
app->exit();
However, my cycle continues when the window closes. I need to determine when the window is closed, so my loop may end. I tried the following. To capture when the window was closed:
connect(app,SIGNAL(lastWindowClosed()),this,SLOT(windowClosed()));
After closing the window, it should be started, but it never starts. It makes fire when I use app->exec()event handling instead of manual.
void QTEngine::windowClosed() {
terminate_loop = true;
}
After further study, the Qt documentation says the following:
[lastWindowClosed] exec(), ( ) .
exec(), . , QWindow ?