Hello,
I’ve been struggling to include VTK into QML. I have installed VTK 9.3 through ninja, following the Kitware’s gitlab docs. I also have set env variables QML_IMPORT_PATH
and QML_IMPORT_PATH
to VTKInstallation/lib/qml/vtk-9.3
. Everything seems to be working, except QTCreator not identifying VTK qml Components
Here is my CmakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(hii VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick OpenGL)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
qt_standard_project_setup(REQUIRES 6.5)
qt_add_executable(apphii
main.cpp
)
qt_add_qml_module(apphii
URI hii
VERSION 1.0
QML_FILES
Main.qml
)
set_target_properties(apphii PROPERTIES
WIN32_EXECUTABLE TRUE
)
target_link_libraries(apphii
PRIVATE Qt6::Quick
${QT_LIBRARIES}
${OPENGL_LIBRARIES}
${VTK_LIBRARIES}
)
include(GNUInstallDirs)
install(TARGETS apphii
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
Now, my Main.qml
contains these VTK lines:
import VTK 9.3 # imports just fine!
...
VTKRenderWindow { # Unknown Component (M300)
id: vtkwindow
width: 400
height: 400
}
The code runs without any problems, nonetheless the qtcreator doesn’t seem to recognize the module’s components.
BTW, the directory VTKInstallation/lib/qml/vtk-9.3
contains qmldir
and plugins.qmltypes
:
qmldir
file:
import QtQuick.tooling 1.2
// This file describes the plugin-supplied types contained in the library.
// It is used for QML tooling purposes only.
//
// This file was auto-generated by:
// 'qmlplugindump -output $qmldir/VTK.9.1/plugins.qmltypes VTK 9.1 $qmldir'
Module {
dependencies: ["QtQuick 2.0"]
Component {
name: "QQuickVTKInteractiveWidget"
prototype: "QObject"
exports: ["VTKWidget 9.1"]
exportMetaObjectRevisions: [0]
Property { name: "enabled"; type: "bool" }
Signal {
name: "enabledChanged"
Parameter { name: "e"; type: "bool" }
}
Method {
name: "sync"
Parameter { name: "ren"; type: "vtkRenderer"; isPointer: true }
}
}
Component {
name: "QQuickVTKRenderItem"
defaultProperty: "data"
prototype: "QQuickItem"
exports: ["VTKRenderItem 9.1"]
exportMetaObjectRevisions: [0]
Property { name: "renderWindow"; type: "QQuickVTKRenderWindow"; isPointer: true }
Method { name: "sync" }
Method { name: "init" }
Method { name: "paint" }
Method { name: "cleanup" }
}
Component {
name: "QQuickVTKRenderWindow"
defaultProperty: "data"
prototype: "QQuickItem"
exports: ["VTKRenderWindow 9.1"]
exportMetaObjectRevisions: [0]
Method { name: "sync" }
Method { name: "init" }
Method { name: "paint" }
Method { name: "cleanup" }
Method { name: "renderNow" }
Method { name: "render" }
}
}
plugins.qmltypes
file:
import QtQuick.tooling 1.2
// This file describes the plugin-supplied types contained in the library.
// It is used for QML tooling purposes only.
//
// This file was auto-generated by:
// 'qmlplugindump -output $qmldir/VTK.9.1/plugins.qmltypes VTK 9.1 $qmldir'
Module {
dependencies: ["QtQuick 2.0"]
Component {
name: "QQuickVTKInteractiveWidget"
prototype: "QObject"
exports: ["VTKWidget 9.1"]
exportMetaObjectRevisions: [0]
Property { name: "enabled"; type: "bool" }
Signal {
name: "enabledChanged"
Parameter { name: "e"; type: "bool" }
}
Method {
name: "sync"
Parameter { name: "ren"; type: "vtkRenderer"; isPointer: true }
}
}
Component {
name: "QQuickVTKRenderItem"
defaultProperty: "data"
prototype: "QQuickItem"
exports: ["VTKRenderItem 9.1"]
exportMetaObjectRevisions: [0]
Property { name: "renderWindow"; type: "QQuickVTKRenderWindow"; isPointer: true }
Method { name: "sync" }
Method { name: "init" }
Method { name: "paint" }
Method { name: "cleanup" }
}
Component {
name: "QQuickVTKRenderWindow"
defaultProperty: "data"
prototype: "QQuickItem"
exports: ["VTKRenderWindow 9.1"]
exportMetaObjectRevisions: [0]
Method { name: "sync" }
Method { name: "init" }
Method { name: "paint" }
Method { name: "cleanup" }
Method { name: "renderNow" }
Method { name: "render" }
}
}
Would someone please why QTCreator doesn’t know about the components?
Thank you very much in advance
Regards