有人可以帮我解决这个问题吗?我正在尝试使用cmakefiles运行应用程序。在程序的主文件中,当程序到达执行QAppication的代码行时,我会遇到分段错误。以下是片段代码:
int main(int argc, char** argv)
{
bool viewing;
parse_command_line( argc, argv );
#ifdef _GRAPHICS_
glutInit(&argc, argv); // note the code runs correctly when this line is excluded and the glutInit was initialized in another class named Viewer (See class Viewer instantiated below), however for my specific application I need to initialize the glutInit in the main program
#endif
if( viewing )
{
#ifdef _GRAPHICS_
QApplication application(argc, argv);
Viewer *viewer = new Viewer( 0, exp, argc, argv );
Interface *render = new Interface( 0, exp, viewer );
render->show();
return application.exec(); //this line causes the segmentation fault
delete viewer;
delete render;
#endif
}
}
答案 0 :(得分:0)
在glutInit
内调用Viewer
时,application
和viewer
会收到所有命令行参数。当你以前调用它时,glutInit
会吃掉它理解的所有参数,因此其他对象可能会遗漏一些参数。
可能的解决方案:执行glutInit
(创建应用程序后),或复制argc / argv。