Qt3d in a MainWindow not working
-
wrote on 27 Jun 2015, 18:35 last edited by bibbinator
Hi,
I'm trying out the new Qt3d stuff in 5.5RC and can't seem to get it to work as a central widget in my MainWindow.I modified the examples to something like this:
view = new QWindow(); QWidget *sceneView = QWidget::createWindowContainer(view); setCentralWidget(sceneView); engine = new Qt3D::QAspectEngine(); engine->registerAspect(new Qt3D::QRenderAspect()); Qt3D::QInputAspect *input = new Qt3D::QInputAspect; engine->registerAspect(input); engine->initialize(); data = new QVariantMap(); data->insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(view))); data->insert(QStringLiteral("eventSource"), QVariant::fromValue(view)); engine->setData(*data);
But this alone causes an error because the surface is not OpenGL.
QOpenGLContext::makeCurrent() called with non-opengl surface 0x7fbe9961c960 Qt3D.Renderer.Backend: bool Qt3D::Render::QGraphicsContext::makeCurrent(QSurface *) makeCurrent failed
Do I need to create some sort of OpenGL widget manually? I see that QGLWidget is deprecated though so not sure how to do that. I thought the createWindowContainer would take into account what kind of view was needed? Or is the problem something else?
Thanks,
Brett -
wrote on 27 Jun 2015, 21:38 last edited by
I modified the code and it works, but crashes sometimes on exit, and there's flickering when more than one window on screen. But putting this here in case others find it helpful.
view = new QWindow(); view->setSurfaceType(QSurface::OpenGLSurface); QSurfaceFormat format; if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) { format.setVersion(4, 3); format.setProfile(QSurfaceFormat::CoreProfile); } format.setDepthBufferSize( 24 ); format.setSamples( 4 ); view->setFormat(format); view->create(); QWidget *sceneView = QWidget::createWindowContainer(view); setCentralWidget(sceneView); ...
The rest of the code I took from simple-cpp example, see the main.cpp for the complete listing.
-
wrote on 1 Jul 2015, 03:32 last edited by audifaxdev 7 Jan 2015, 03:34
Hey buddy,
I am not sure if using QWidget is meant to work with Qt3D. Anyway, instantiate a custom QWindow with OpenGL surface works for me (like you did and like in the examples) :
The View / Window subclass :
View::View(QScreen *screen) : QWindow(screen) { setSurfaceType(QSurface::OpenGLSurface); resize(1024, 768); QSurfaceFormat format; if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) { format.setVersion(4, 3); format.setProfile(QSurfaceFormat::CoreProfile); } format.setDepthBufferSize( 24 ); format.setSamples( 4 ); setFormat(format); create(); }
And then from the main :
QGuiApplication a(argc, argv); View view; Qt3D::QAspectEngine engine; engine.registerAspect(new Qt3D::QRenderAspect()); Qt3D::QInputAspect *input = new Qt3D::QInputAspect; engine.registerAspect(input); engine.initialize(); QVariantMap data; data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(&view))); data.insert(QStringLiteral("eventSource"), QVariant::fromValue(&view)); engine.setData(data);
Hope that'll help !
3/3