成功编译后,Qt3D Project不显示任何结果

时间:2018-10-06 17:15:26

标签: c++ qt

当我编译我的Qt3D项目时,一切都很好,但是启动之后什么也没发生(没有打开新窗口)。在Qt控制台中,据说该程序已成功启动,我什至可以在Windows Task Manager中找到我的应用程序的进程,但是大约30秒后,Qt表示该应用程序突然关闭(在此期间未打开新窗口)。我的main.cpp代码:

#include <QGuiApplication>
#include <Qt3DCore>
#include <Qt3DExtras>
#include <Qt3DRender>

Qt3DCore::QEntity *createScene();

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    Qt3DExtras::Qt3DWindow window;

    Qt3DCore::QEntity *rootEntity = createScene();

    Qt3DRender::QCamera *camera = window.camera();
    camera->lens()->setPerspectiveProjection(60.0f, float(window.width()) / window.height(), 0.1f, 1000.0f);
    camera->setPosition(QVector3D(0.0f, 0.0f, 40.0f));
    camera->setViewCenter(QVector3D(0.0f, 0.0f, 0.0f));

    window.setRootEntity(rootEntity);
    window.show();
    return app.exec();
}

Qt3DCore::QEntity *createScene()
{
    Qt3DCore::QEntity *resultEntity = new Qt3DCore::QEntity;

    Qt3DExtras::QTorusMesh *torusMesh = new Qt3DExtras::QTorusMesh(resultEntity);
    torusMesh->setRadius(15.0f);
    torusMesh->setMinorRadius(6.0f);
    torusMesh->setSlices(16);
    torusMesh->setRings(32);

    Qt3DExtras::QPhongMaterial *torusMaterial = new Qt3DExtras::QPhongMaterial(resultEntity);

    Qt3DCore::QTransform *torusTransform = new Qt3DCore::QTransform(resultEntity);

    resultEntity->addComponent(torusMesh);
    resultEntity->addComponent(torusMaterial);
    resultEntity->addComponent(torusTransform);

    return resultEntity;
}

0 个答案:

没有答案