Qt 3D: Simple C++ Example¶
A C++ application that demonstrates how to render a scene in Qt 3D.
Simple demonstrates how to render a scene in Qt 3D.
Running the Example¶
To run the example from Qt Creator , open the Welcome mode and select the example from Examples. For more information, visit Building and Running an Example.
Setting Up the Scene¶
We set up the scene in the main.cpp file.
To be able to use the classes and functions in the Q3D Core, Q3D Render, Qt 3D Input, and Qt 3D Extras modules, we must include the classes:
First, we set up the scene and specify its root entity:
We specify the material to use for Phong rendering:
The root entity is just an empty shell and its behavior is defined by the components that it references. We specify the torus entity and its mesh, transform, and material components:
We also specify a sphere entity and its components:
We use a property animation to animate the sphere transform.
Finally, we initialize a Qt GUI application that uses a Qt 3D window:
© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.