当前,我正在尝试在Qt3D应用程序中导入场景。 问题是,当从QSceneLoader创建实例并设置源的QUrl并将其添加到Entity时,它将冻结应用程序,直到完成导入。
我试图将其放入线程,如:
void start()
{
qDebug() << "Thread";
QAspectEngine* pAs = new QAspectEngine();
pAs->registerAspect(new QRenderAspect());
QRenderSettings *renderSettings = new QRenderSettings();
renderSettings->setActiveFrameGraph(new Qt3DExtras::QForwardRenderer());
// Root entity
Qt3DCore::QEntity *sceneRoot2 = new Qt3DCore::QEntity();
sceneRoot2->addComponent(renderSettings);
pAs->setRootEntity(QSharedPointer<QEntity>(sceneRoot2));
Qt3DRender::QSceneLoader *sceneLoader = new Qt3DRender::QSceneLoader();
SceneWalker sceneWalker(sceneLoader);
QObject::connect(sceneLoader, &Qt3DRender::QSceneLoader::statusChanged, &sceneWalker, &SceneWalker::onStatusChanged);
sceneLoader->setSource(QUrl::fromLocalFile("C:/Users/USER/Downloads/TreeTest.obj"));
sceneRoot2->addComponent(sceneLoader);
}
当QThread发出启动信号时,该函数将运行,但是我得到了:QObject::setParent: Cannot set parent, new parent is in a different thread.
所以我不知道如何在不冻结应用程序的情况下在Qt3D中导入场景,有什么可以帮助的吗?