1

Trying to create a 3D Render of my object and put it into QWidget app, but I got some problem with transforming Q3DWidget into QWidget. I'm a novice in Qt and I'm sorry in advance for some ridiculous mistakes, if I have em. There is how I attempted to do it:

    Qt3DExtras::Qt3DWindow view;

    Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity;
    Qt3DCore::QEntity *model = new Qt3DCore::QEntity(rootEntity);

    Qt3DExtras::QPhongMaterial *material = new Qt3DExtras::QPhongMaterial();
    material->setDiffuse(QColor(125, 125, 125));

    Qt3DRender::QMesh *modelMesh = new Qt3DRender::QMesh;
    QUrl data = QUrl::fromLocalFile("C:\\CDH\\model.stl");
    modelMesh->setMeshName("Device model");
    modelMesh->setSource(data);
    model->addComponent(modelMesh);
    model->addComponent(material);

    Qt3DRender::QCamera *camera = view.camera();
    camera->lens()->setPerspectiveProjection(40.0f, 16.0f/9.0f, 0.1f, 1000.0f);
    camera->setPosition(QVector3D(0, 0, 40.0f));
    camera->setViewCenter(QVector3D(0, 0, 0));

    Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity);
    Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity);
    light->setColor("black");
    light->setIntensity(0.8f);
    lightEntity->addComponent(light);

    Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity);
    lightTransform->setTranslation(QVector3D(60, 0, 40.0f));
    lightEntity->addComponent(lightTransform);

    Qt3DExtras::QOrbitCameraController *camController = new 
    Qt3DExtras::QOrbitCameraController(rootEntity);
    camController->setCamera(camera);
    view.setRootEntity(rootEntity);
    view.show();

    QWidget *w = QWidget::createWindowContainer(&view);

    //some widget handling

    w->show();

It builds (MinGW 7.3.0) well, without errors and warning, but it just crashes when I try to launch an application.

Thanks in advance for your replies!

Anatoly
  • 25
  • 5
  • `view.show();` could be redundant as long as it is nested to the window container. Other than that, you could have other problems, say, in the way the app starts. From here it is absolutely not clear where the application object is and how exactly it does exec() so that `view` is not destroyed too soon. – Alexander V Jan 27 '20 at 18:41
  • @alexander-v The code in a question is full code of void render3D() function, that function is called at the very beginning of mainwindow(), right after "ui -> setupUi(this)". "//some widget handling" is inserting QWidget w into QStackedWidget and setting current index of that QStackedWidget. I also tried to remove view.show() from my code, but the application crashes too, but there is a new error here: "Failed to make context current: OpenGL resources will not be destroyed". Also, I found that "view.setRootEntity(rootEntity);" string causes crashing. Thank you for your reply! – Anatoly Jan 28 '20 at 02:18
  • You may need to dynamically allocate your `view` variable, e.g. `Qt3DExtras::Qt3DWindow* view = new Qt3DExtras::Qt3DWindow;` as it goes out of scope, if the function ends. – vre Jan 28 '20 at 10:43
  • @vre Thank you for your reply! I tried your way to fix that problem, but the application still crashes. I can't solve these problem for 2 days already, so I just copied the ["Qt3D Simple C++ Example"](https://doc.qt.io/qt-5/qt3d-simple-cpp-example.html) and tried to run that, but my application still crashes and there are new error: `QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined`. I don't understand what is happening and I feel depression... :( – Anatoly Jan 29 '20 at 06:26
  • I don't think the `...swapBuffers()` is part of the root cause of your issue. Have seen that on other running programs too without crashes. Can you provide us with the output of the program when it crashes? On Windows there must have been an error dialog popped up providing more information. Press `Ctrl+C` on this dialog to copy the message contents to the clipboard and add this information to your question. Maybe you need to add the binaries directory of Qt to the `PATH` environment variable. But this cannot be derived from the terse information you gave about the crash. – vre Jan 29 '20 at 07:17
  • @vre it's strange, but there are no errors when the application crashes. If I run it directly from Qt Creator there are only `The program has unexpectedly finished`, `The process was ended forcefully` and `C:\build-CDH-Desktop_Qt_5_14_0_MinGW_64_bit-Release\CDH.exe crashed` messages. Nothing more. If I try to run it from compiled .exe the application just doesn't start. UPD: in "General Messages" tab there is the interesting message: `Clang Code Model: Error: The clangbackend executable "C:\Qt\Qt5.14.0\Tools\QtCreator\bin\clangbackend.exe" could not be started (timeout after 10000ms)` – Anatoly Jan 29 '20 at 07:48
  • What puzzles me is that even the `Simple C++ Example` does not run. Can you run Dependency Walker on this sample executable? http://www.dependencywalker.com/ It scans the executable for the DLLs needed. Maybe one of them is missing. – vre Jan 29 '20 at 07:54
  • @vre Sorry for long not replying, was really busy with my travel to another city. I ran dependencywalker and found out huge amount of missing DLL's, can't attach them all, but all of them are starting with `API-MS-...` or `EXT-MS-...` + two more DLL's `HVSIFILETRUST.DLL` and `IESHIMS.DLL`. – Anatoly Jan 30 '20 at 03:50
  • @vre I found that removing all 3D components and all code of rendering from project don't change dependency walker output, the application doesn't crash and work right but dependency walker anyway show huge amount of missing DLLs. – Anatoly Jan 31 '20 at 09:57
  • Those `EXT-MS-` and `API-MS-` DLLs are MS internal and resolved in a different way So no need to worry. `IESHIMS.DLL` is an internal DLL that is delay loaded when needed, so also no need to worry. So I am out of ideas for now. Maybe you have another Qt installation in the path before your MinGW based one? – vre Jan 31 '20 at 13:34
  • Yes, the problem was in environment. I still don't understand what kind of problem it was, but full Windows reinstallation (also project migration to another workstation) helped me. – Anatoly Feb 10 '21 at 16:59

0 Answers0