How can I load a 3D model(like *.obj files etc.) in QT

  • HI,
    Now, I am doing a project in which I want to display a 3D model(robot) and control it like moving its leg or arm.
    So, I am trying to load a *.obj files into QT, but I failed.
    I search on the Internet and some people say I can try the Assimp, but i can't find how to use it. I include <AssimpIO> but resulted in a "file not found" compiler error. it seems QT do not support Assimp now?
    Is there any way to load 3D model(like *.obj files etc.) into QT?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you took a look at the Qt3D module documentation and the accompanying examples ?

    The Audio Visualizer Example loads .obj files.

    By the way, it's Qt. QT stands for Apple QuickTime which doesn't seem to be what you are looking for.

  • This post is deleted!

  • @SGaist Thank you very much. Acctually I want find a example using C++ to load 3D model, but the Audio Visualizer Example still help me a lot. I will study this example carefully.
    I still very much appreciate your help~

  • Qt 3D initially support obj modules without materials. Take a try.

  • @jiancaiyang Thanks, I have found the Qt Documentation about the Qt 3D C++ Classes( and I know there is a AssimpIO Class(, but i can't use it(I include <AssimpIO> but resulted in a "file not found" compiler error ) I don't whether QT don't support Assimp now or not. is there any way to load obj modules except AssimpIO Class?

  • Lifetime Qt Champion

    Which version of Qt are you using ?

    Did you add QT += 3drender to your .pro file ? If so, did you re-run qmake after that ?

  • I did it this way in Qt3D:

    1. Create a .qrc file as resource
    2. add it to your .pro:
    RESOURCES += \
    1. content of .qrc file looks like this, make sure the .obj file is in the right directory:
        <qresource prefix="/">
    1. create a QEntity with all needed components like QTransform, QMaterial and especially QMesh
    2. Add the .obj as source for the mesh:
        Qt3DRender::QMesh *mesh = new Qt3DRender::QMesh();
    1. Add mesh and other components to entity:
    Qt3DCore::QEntity *object = new Qt3DCore::QEntity(rootEntity);
    1. Finished

  • Thanks for all the help.I have found to load the 3D model file(.obj) into Qt and control it.
    Initially, I try to use C++ to complete all the function(display and control), but I find it a little complex for me. So I decide using QML to display the model and using C++ to control it.

    I post the approach I used:

    First, loading and displaying the 3D model using QML, you can refer to Qt 3D: Wireframe QML Example and Qt 3D: Scene3D QML Example. I think these two example include almost all the detail you need when loading and displaying the 3D model.

    Second, i notice Entity has a property:Transform, which decide the position and angle of the 3D model displaying in the scene. The Transform accept scale, matrix, translation or rotation to define the property. So i define a C++ class, the class has some member variables that are QMatrix4x4 type. Obviously, I use QMatrix4x4 to store the coordinate matrix.

    Third, I export the C ++ object into QML as a property that QML can use(refer to setContextProperty).

    Fourth, bind property like this:
    Transform {
    id: transform
    matrix: matrix.matrix

    Fifth, when i want to change the position or angle, i just use C++ to change the QMatrix4x4 member variables, QML will update the scene automatically.


  • @guy-incognito Thank you for your help. Finally I use QML to display the 3D model and C++ to control it, but you still help me a lot. Thanks

Log in to reply