render 3d model with qml in qquickwidget
up vote
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: sceneRoot
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)
...
}
Then i get another warnning: ReferenceError: _window is not defined, and 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!
c++ 3d qquickwidget
add a comment |
up vote
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: sceneRoot
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)
...
}
Then i get another warnning: ReferenceError: _window is not defined, and 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!
c++ 3d qquickwidget
add a comment |
up vote
0
down vote
favorite
up vote
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: sceneRoot
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)
...
}
Then i get another warnning: ReferenceError: _window is not defined, and 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!
c++ 3d qquickwidget
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: sceneRoot
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)
...
}
Then i get another warnning: ReferenceError: _window is not defined, and 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!
c++ 3d qquickwidget
c++ 3d qquickwidget
edited Nov 5 at 3:43
asked Nov 3 at 14:35
Bruce
44
44
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53132333%2frender-3d-model-with-qml-in-qquickwidget%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password