Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt3d in a MainWindow not working
Forum Updated to NodeBB v4.3 + New Features

Qt3d in a MainWindow not working

Scheduled Pinned Locked Moved General and Desktop
qt3dmainwindowwidget
3 Posts 2 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • bibbinatorB Offline
    bibbinatorB Offline
    bibbinator
    wrote on last edited by bibbinator
    #1

    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

    1 Reply Last reply
    0
    • bibbinatorB Offline
      bibbinatorB Offline
      bibbinator
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        audifaxdev
        wrote on last edited by audifaxdev
        #3

        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 !

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved