Qt+OSG编译成功后,例子运行时弹出出错:Cannot make QOpenGLContext current in a different thread.

BenBenDeYiZhi 2017-12-20 11:13:03
Qt5.4.2+OSG3.2+vs2010+win10_X64,编译成功后,也进行了环境变量配置,能做的什么都做了,然后建了一个QtApplication,在网上复制了一段代码,出现错误,代码和错误如下:
代码:
#include <QtWidgets/QApplication>

#include <osgViewer/Viewer>
#include <osgGA/TrackballManipulator>
#include <osgQt/GraphicsWindowQt>

#include <osg/ShapeDrawable>
#include <osg/MatrixTransform>
#include <osgManipulator/TabBoxDragger>
#include <osgGA/StateSetManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgDB/ReadFile>



int main( int argc, char** argv )
{
QApplication app(argc, argv);
osgQt::initQtWindowingSystem();

osg::Group* sceneroot = new osg::Group;

sceneroot->addChild(osgDB::readNodeFile("cow.osg"));
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
viewer->addEventHandler( new osgGA::StateSetManipulator(viewer->getCamera()->getOrCreateStateSet()) );
viewer->addEventHandler(new osgViewer::StatsHandler);


viewer->setSceneData( sceneroot );
viewer->setCameraManipulator( new osgGA::TrackballManipulator );
osgQt::setViewer( viewer.get() );

osgQt::GLWidget* glw = new osgQt::GLWidget;
osgQt::GraphicsWindowQt* graphicswin = new osgQt::GraphicsWindowQt(glw);

viewer->getCamera()->setViewport( new osg::Viewport(0, 0, glw->width(), glw->height() ) );
viewer->getCamera()->setGraphicsContext( graphicswin );

glw->show();

return app.exec();
}

错误:
1>C:\OSG\include\osgQt/GraphicsWindowQt(24): fatal error C1083: 无法打开包括文件:“QGLWidget”: No such file or directory

现在上述错误解决了,可以编译通过,但是运行时弹出错误:Cannot make QOpenGLContext current in a different thread.
具体错误看图。
...全文
1704 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hankern 2018-09-19
  • 打赏
  • 举报
回复
https://blog.csdn.net/hankern/article/details/81734709
longlongway2012 2018-07-26
  • 打赏
  • 举报
回复
设置为单线程试试吧

24,852

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧