Important: Please read the Qt Code of Conduct -

How to access QML Surface3DSeries from C++?

  • How to access a qml Surface3DSeries object from C++?
    I’m having serious problems with the QObject::findChildren() approach. My main.qml declares a Surface3D with objectName “mySurface” and a Surface3DSeries item with objectName: “mySurfaceSeries”, something like this:

     Surface3D {
               objectName: "mySurface"
               width: parent.width
               height: parent.height
               Surface3DSeries {
                    objectName: "mySurfaceSeries"
                   ItemModelSurfaceDataProxy {

    After loading the qml in main.cpp, my C++ code calls rootObject->findChildren<QObject *>(). The returned object tree contains object “mySurface” but does NOT contain object “mySurfaceSeries”. I have no idea why - I thought that every item in qml would be represented in the object tree. There are no obvious errors in the qml, and the Surface3D is displayed properly with data provided by the Surface3DSeries.

    The tree's “myService” object is not a Q3DSurface (through which I could access the series) but rather a QtDataVisualization::DeclarativeSurface which is not described anywhere that I can find. The DeclarativeSurface class is defined in qtdatavis3d/src/datavisualizationqml2/declarativesurface_p.h and contains a promising method seriesList() - but QtCreator says “No type named ‘DeclarativeSurface’ in namespace ‘QtDataVisualization’”, apparently that file is not in QtCreator’s include-file path.

    So I am at a loss right now - how can I access Surface3DSeries from C++?


Log in to reply