[尝试创建我的对象的3D渲染并将其放入QWidget应用程序,但是将Q3DWidget转换为QWidget时遇到了一些问题。我是Qt的新手,如果遇到em,我对某些荒谬的错误感到抱歉。我尝试过这样做:
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();
它可以很好地构建(MinGW 7.3.0),没有错误和警告,但是当我尝试启动应用程序时,它只是崩溃了。
感谢您的答复!
您曾经摆脱这个问题吗?我正面临着同一个人并且被卡住了...谢谢和kr Herwig