Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to use Qt's DeclarativeSurface in my app?



  • Specifically, how can I build and link with DeclarativeSurface which is defined in /qtdatavis3d/src/datavisualizationqml2?

    I'm developing an app with QML-defined UI and C++ singleton back-end. I'm using Qt v5.14.2. My QML includes a Surface3D item and I want to manipulate it from the C++ back-end.
    The C++ back-end locates the Surface3D item in the root window object tree, and its className is "QtDataVisualization::DeclarativeSurface" - it's NOT QtDataVisualization::Q3DSurface, for some reason. Qt's include/QtDataVisualization directory does not have a file named "DeclarativeSurface". A search shows that class DeclarativeSurface is defined in datavisualizationqml2/declarativesurface_p.h. and datavisualizationqml2/declarativesurface.cpp. I include declarativesurface_p.h in my app, invoke DeclarativeSurface methods on the object from C++, and it compiles. But I get "undefined reference" errors at link time.

    What is the trick to using DeclarativeSurface? I am using qtcreator v4.5.2

    Thanks
    Tom



  • The DeclarativeSurface header file declarativesurface_p.h contains this disclaimer:

    //  W A R N I N G
    //  -------------
    //
    // This file is not part of the QtDataVisualization API.  It exists purely as an
    // implementation detail.  This header file may change from version to
    // version without notice, or even be removed.
    //
    // We mean it.
    

    From the above, it's pretty clear that the API currently has no supported way of accessing QML Surface3D from C++ - use this class at your own risk. There are no doxygen comments in that file, so user "interpretation" is required to figure out how the methods are to be used.

    Note that DeclarativeSurface is in namespace QtDataVisualization, but since it's not "formally" a part the API, several additional directories must be specified in INCLUDEPATH; my app's myApp.pro looks like this, where $QT is my QT source directory:

    INCLUDEPATH += $QT/5.14.2/Src/qtdatavis3d/src/
    INCLUDEPATH += $QT/5.14.2/Src/qtdatavis3d/src/datavisualization/global
    INCLUDEPATH += $QT/5.14.2/Src/qtdatavis3d/src/datavisualization/engine/
    INCLUDEPATH += $QT/5.14.2/Src/qtdatavis3d/src/datavisualization/data/
    INCLUDEPATH +=$QT/5.14.2/Src/qtdatavis3d/src/datavisualization/theme
    INCLUDEPATH += $QT/5.14.2/Src/qtdatavis3d/src/datavisualizationqml2
    

    I am developing for a desktop Linux target, and the DeclarativeSurface code is in library $QT/5.14.2/gcc_64/qml/QtDataVisualization/libdatavisualizationqml2.so


Log in to reply