Important: Please read the Qt Code of Conduct -

How to load *.ply content properly

  • Hello everybody,

    i am quite new to work with 3D content in qt and i got a question regarding the proper loading of *.ply formats. I created a small example, based on the basicshapes-example from qt, just loading my personal .ply file, instead of using the predefined 3D-meshes.

    // code
    int main(int argc, char **argv)
    QApplication app(argc, argv);
    Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow();
    QWidget *container = QWidget::createWindowContainer(view);
    QSize screenSize = view->screen()->size();
    container->setMinimumSize(QSize(200, 100));

    QWidget *widget = new QWidget;
    QHBoxLayout *hLayout = new QHBoxLayout(widget);
    hLayout->addWidget(container, 1);
    widget->setWindowTitle(QStringLiteral("Basic shapes"));
    Qt3DInput::QInputAspect *input = new Qt3DInput::QInputAspect;
    // Root entity
    Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity();
    // Camera
    Qt3DRender::QCamera *cameraEntity = view->camera();
    cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 100000.0f);
    cameraEntity->setPosition(QVector3D(-30000, 0, 20000.0f));
    cameraEntity->setUpVector(QVector3D(0, 0, 1));
    cameraEntity->setViewCenter(QVector3D(0, 0, 10000));
    Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity);
    Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity);
    Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity);
    //Loading .ply data
    QUrl data = QUrl::fromLocalFile("demo_data.ply");
    qDebug() << data << data.isValid() << data.toLocalFile() << QFileInfo(data.toLocalFile()).exists() << data.fileName();
    Qt3DRender::QMesh *bodyMesh = new Qt3DRender::QMesh();
    Qt3DCore::QTransform *bodyTransform = new Qt3DCore::QTransform;
    bodyTransform->setScale3D(QVector3D(10.0, 10.0, 10.0));
    Qt3DExtras::QPhongMaterial *bodyMaterial = new Qt3DExtras::QPhongMaterial();
    Qt3DCore::QEntity *plyEntity = new Qt3DCore::QEntity(rootEntity);
    // Set root object of the scene
    // Show window
    widget->resize(1200, 800);
    return app.exec();


    This works fine on my machine, in Visual Studio as well as using the executable directly. Now I want to take this small programm to another windows machine. The original basicshapes example runs perfectly fine on the other machine, my version does not. The 3D content is not loaded, the Qt3DRender::QMesh::Status function returns a 3 (An error occurred while loading the mesh). So it seems to be a problem on loading the *.ply file, which is stored in the same folder as the executable. The line

    qDebug() << data << data.isValid() << data.toLocalFile() << QFileInfo(data.toLocalFile()).exists() << data.fileName();

    says "true" for the QFileInfo(data.toLocalFile()).exists() part.

    So I don't know, why the 3D data cannot be loaded. Any suggestions? Any additional libs I need to add?

    Thanks a lot,


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you do a complete deployment of your application using windeployqt ? You might be missing some plugins otherwise.

    By the way, what version of Qt are you using ?

  • @SGaist Man, you saved my day. I didn't know this one and it completely worked so far. Thank's a lot!!

Log in to reply