Unsolved render 3d model with qquickwidget
-
0
down vote
favorite
I use Qt 5.5.1 in ubuntu 18.04, I want to render a 3d model(.obj format) with qml in a qquickwidget), i use setSource founction to bind qml file to the qquickwidget, my qml file coded as bollow:import Qt3D 2.0
import Qt3D.Renderer 2.0
import QtQuick 2.0
Entity {
id: root
Camera {
id: camera
projectionType: CameraLens.PerspectiveProjection
fieldOfView: 45
aspectRatio: _window.width / _window.height
nearPlane: 0.1
farPlane: 1000.0
position: Qt.vector3d(0.0, 10.0, 20.0)
viewCenter: Qt.vector3d(0.0, 0.0, 0.0)
upVector: Qt.vector3d(0.0, 1.0, 0.0)
}property Material material
Mesh {
id: trefoilMesh
source: "../res/obj/model.obj"
}Transform {
id: j2Transform
...
}
}
but when i run, i got some error: QQuickWidget only supports loading of root objects that derive from QQuickItem. If your example is using QML 2, (such as qmlscene) and the .qml file you loaded has 'import QtQuick 1.0' or 'import Qt 4.7', this error will occur. To load files with 'import QtQuick 1.0' or 'import Qt 4.7', use the QDeclarativeView class in the Qt Quick 1 module.then I wraped my qml body whit Item property, some thing like that:
Item {
id: root
Entity {
id: sceneRootCamera { id: camera projectionType: CameraLens.PerspectiveProjection fieldOfView: 45 aspectRatio: _window.width / _window.height nearPlane: 0.1 farPlane: 1000.0 position: Qt.vector3d(0.0, 10.0, 20.0) viewCenter: Qt.vector3d(0.0, 0.0, 0.0) upVector: Qt.vector3d(0.0, 1.0, 0.0)
...
}
Then i can fix the error, but on the widget, I got an empty output. And then I use the Qt3D::Quick::QQmlAspectEngine and QWindow to render the qml(without Item property wraped) as the qt example, i cant got the correct model on the window, so i think my qml file is ok. But the problem is I can't use the QWindow, i need to embed my 3d model render as a part of my program(already have a mainwindow), can anyone help me how to do this? Thank you very much!