我正在开发一个模拟器。我为 GUI 选择了 QT。我的项目涉及大量数据操作,我使用 QT 只是为了绘制我的结果。
我的代码结构是这样的,我的主函数包含我的数据的全局对象、QT GUI 的对象和用于操作此数据的其他对象。我需要每 30 毫秒修改一次这些数据。我还附上了我的主文件的简化版本。
我的问题是在退出 QT 对象之前我无法调用其他对象(GUI 除外)的函数。我已经在 QT 中单独实现了计时器,它可以绘制新数据并且工作正常。我要做的就是在独立于 QT 对象的特定时间间隔调用我的 ai 和 phySim 对象。我希望这三个对象完全独立。
world* _world;
int main(int argc, char *args[])
{
_world = new world();
gui *GUI; ///QT object
ai *AI;//object to manipulate data
phySim *sim;//object to manipulate data
/////////////////////////////////// this gets executed only when i close the QT gui
AI = new ai(_world);
AI->doSomething();
sim = new phySim(_world);
sim->updateWorld();
//////////////////////////////////////////////////////////////////////////////
QApplication app(argc,args);
GUI = new gui(_world);
GUI->show();
return app.exec();
}