Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在Qt窗口内运行游戏循环_C++_Qt - Fatal编程技术网

C++ 在Qt窗口内运行游戏循环

C++ 在Qt窗口内运行游戏循环,c++,qt,C++,Qt,如何在Qt窗口内运行游戏循环而不创建新线程 我的“RunFrame”方法如下所示: void GameWindow::RunFrame() { // Update the game time. gameTime.Update(); timeBehind += gameTime.TotalTime() - lastTime; lastTime = gameTime.TotalTime(); while( timeBehind >= targetTim

如何在Qt窗口内运行游戏循环而不创建新线程

我的“RunFrame”方法如下所示:

void GameWindow::RunFrame()
{
    // Update the game time.
    gameTime.Update();
    timeBehind += gameTime.TotalTime() - lastTime;
    lastTime = gameTime.TotalTime();

    while( timeBehind >= targetTimeStep )
    {
        Update();
        timeBehind -= targetTimeStep;
    }

    Draw();
    SwapBuffers();
}

正如您所看到的,它的运行就像每个事件循环都被调用一样。有没有一种方法可以让我的窗口中的方法在每个事件循环中都被调用?或者我应该重新设计Qt中计时器的循环?

我认为QTimer是一个有效且相对简单的解决方案。它使用多媒体定时器(如果需要的话)来达到毫秒级的分辨率,所以在游戏循环中是可行的