i have several issues here. first, when I enabled vtk_build_examples in cmake, but the generated vs2022 solution does not have any example directory to check, how does it work here.
secondly, i have hard time to run QML/vtk in release build, in debug build it works, but not release, and there is no clue what happens, even the simplest example won’t work。
#include <QtQml/QQmlApplicationEngine>
#include <QtQuick/QQuickWindow>
#include <QtGui/QGuiApplication>
#include <QtGui/QSurfaceFormat>#include <QQuickVTKItem.h>
#include <QVTKRenderWindowAdapter.h>#include <vtkActor.h>
#include <vtkConeSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>struct MyVtkItem : QQuickVTKItem
{
vtkUserData initializeVTK(vtkRenderWindow* renderWindow) override
{
// Create a cone pipeline and add it to the view
vtkNew cone;vtkNew<vtkPolyDataMapper> mapper; mapper->SetInputConnection(cone->GetOutputPort()); vtkNew<vtkActor> actor; actor->SetMapper(mapper); vtkNew<vtkRenderer> renderer; renderer->AddActor(actor); renderer->ResetCamera(); renderer->SetBackground(0.0, 1.0, 1.0); renderer->SetBackground2(1.0, 0.0, 0.0); renderer->SetGradientBackground(true); renderWindow->AddRenderer(renderer); renderWindow->SetMultiSamples(16); return nullptr; }
};
int main(int argc, char* argv)
{
QQuickVTKItem::setGraphicsApi();#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endifQGuiApplication app(argc, argv); qmlRegisterType<MyVtkItem>("com.vtk.example", 1, 0, "MyVtkItem"); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/testRelease4/qml/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec();
}
main.qml
import QtQuick 2.9
import QtQuick.Window 2.2
import com.vtk.example 1.0Window {
id: win
visible: true
width: 640
height: 640
title: qsTr(“Hello World”)Rectangle {
anchors.fill: parent
color: “darkseagreen”
}Rectangle {
id: r
border { width: 5; color: “steelblue” }
radius: 5
color: “hotpink”
anchors.fill: parent
anchors.margins: 100MyVtkItem { id: vtk anchors.fill: parent anchors.margins: 5 opacity: 0.7 }
}
Rectangle {
anchors.leftMargin: parent.width/2
anchors.topMargin: parent.height/2
anchors.fill: parentborder { width: 5; color: "gold" } radius: 11 color: "peachpuff" opacity: 0.8
}
}
main.qml
with debug build it works fine, but with release build it says
QQmlApplicationEngine failed to load component
qrc:/testRelease4/qml/main.qml:25:5: Cannot assign object to list property “data”