# Cope & Run FourPaneViewer Demo in QtCreator with cmake

**URL:** <https://discourse.vtk.org/t/cope-run-fourpaneviewer-demo-in-qtcreator-with-cmake/14771>\
**Category:** Development\
**Tags:** code\
**Created:** [October 26, 2024, 7:25am UTC](https://discourse.vtk.org/t/cope-run-fourpaneviewer-demo-in-qtcreator-with-cmake/14771 "2024-10-26T07:25:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhuofalin](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhuofalin/32/7146_2.png) [@zhuofalin](https://discourse.vtk.org/u/zhuofalin)\
**Post date:** [October 26, 2024, 7:25am UTC](https://discourse.vtk.org/t/cope-run-fourpaneviewer-demo-in-qtcreator-with-cmake/14771/1 "2024-10-26T07:25:57Z")

</div>

Hello,everyone 😭 can you help me? 🫡  
I encountered the following problem when I copied and ran the [FourPaneViewer code](https://github.com/Kitware/VTK/tree/master/Examples/GUI/Qt/FourPaneViewer) in Qtcreator today. There are so many **\_\_imp\_\_xxxx** flags and too many errors make me nervous and doubtful: What should I do?  
**Error** :

 ![error_image](https://discourse.vtk.org/uploads/default/original/2X/7/7a1cfa74389af56028c09d8e8b01341ab5241978.png)  
**Environment** :  
Windows10, QtCreator with Qt6.8.0, vtk9.3.1(which build debug mode)  
**Changed** :  
I just separated the vtkResliceCursorCallback class inherited from the vtkCommand class and wrote it into vtkResliceCursorCallback.h and vtkResliceCursorCallback.cpp.this is my demo tree.  
 ![demo_tree](https://discourse.vtk.org/uploads/default/original/2X/4/41bfcffb21e0739adfc65294df158756beff23b3.png)  
**CMakeLists.txt** :

```auto
cmake_minimum_required(VERSION 3.16)
project(QtVtkRenderWindowsUpdate VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(VTK_DIR "./vtk_build_ninja_D/lib/cmake/vtk-9.3")
find_package(VTK
  COMPONENTS
    CommonCore
    GUISupportQt
    IOImage
    ImagingColor
    ImagingGeneral
    InteractionImage
    InteractionStyle
    InteractionWidgets)
if (NOT VTK_FOUND)
  message("Skipping example: ${VTK_NOT_FOUND_MESSAGE}")
  return ()
endif ()

set(QT6_DIR "E:/qqt/6.8.0/msvc2022_64/lib/cmake/Qt6")
set(Qt6Quick_DIR "E:/qqt/6.8.0/msvc2022_64/lib/cmake/Qt6Quick")
set(Qt6QuickTools_DIR "E:/qqt/6.8.0/msvc2022_64/lib/cmake/Qt6QuickTools")
set(Qt6Gui_DIR "E:/qqt/6.8.0/msvc2022_64/lib/cmake/Qt6Gui")
set(Qt6GuiTools_DIR "E:/qqt/6.8.0/msvc2022_64/lib/cmake/Qt6GuiTools")
set(Qt6Widgets_DIR "E:/qqt/6.8.0/msvc2022_64/lib/cmake/Qt6Widgets")
set(Qt6WidgetsTools_DIR "E:/qqt/6.8.0/msvc2022_64/lib/cmake/Qt6WidgetsTools")
set(Qt6OpenGL_DIR "E:/qqt/6.8.0/msvc2022_64/lib/cmake/Qt6OpenGL")
set(Qt6OpenGLWidgets_DIR "E:/qqt/6.8.0/msvc2022_64/lib/cmake/Qt6OpenGLWidgets")

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Core)

set(PROJECT_SOURCES
        main.cpp
        vtkResliceCursorCallback.h
        vtkResliceCursorCallback.cpp
        qtvtkrenderwindows.cpp
        qtvtkrenderwindows.h
        qtvtkrenderwindows.ui
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(QtVtkRenderWindowsUpdate
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
        Icons/icons.qrc
    )
# Define target properties for Android with Qt 6 as:
# set_property(TARGET QtVtkRenderWindowsUpdate APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(QtVtkRenderWindowsUpdate SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(QtVtkRenderWindowsUpdate
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_link_libraries(QtVtkRenderWindowsUpdate PRIVATE ${VTK_LIBRARIES} Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Core)
target_include_directories(QtVtkRenderWindowsUpdate PRIVATE ${VTK_INCLUDE_DIRS})
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.QtVtkRenderWindowsUpdate)
endif()
set_target_properties(QtVtkRenderWindowsUpdate PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)

install(TARGETS QtVtkRenderWindowsUpdate
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(QtVtkRenderWindowsUpdate)
endif()

vtk_module_autoinit(TARGETS QtVtkRenderWindowsUpdate MODULES ${VTK_LIBRARIES})

```

😇 **I hope to get some help from all the masters passing by. I would like to thank you in advance**. 😇

---

<div class="post-metadata">

**Author:** ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)\
**Post date:** [October 27, 2024, 2:51pm UTC](https://discourse.vtk.org/t/cope-run-fourpaneviewer-demo-in-qtcreator-with-cmake/14771/2 "2024-10-27T14:51:02Z")

</div>

Can you verify that you are not linking to a release build from a debug build.

---

<div class="post-metadata">

**Author:** ![zhuofalin](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhuofalin/32/7146_2.png) [@zhuofalin](https://discourse.vtk.org/u/zhuofalin)\
**Post date:** [November 9, 2024, 10:20am UTC](https://discourse.vtk.org/t/cope-run-fourpaneviewer-demo-in-qtcreator-with-cmake/14771/3 "2024-11-09T10:20:54Z")

</div>

Thanks for your help 🫡 I will try it soon~~~

---

<div class="post-metadata">

**Author:** ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)\
**Post date:** [December 5, 2024, 5:19pm UTC](https://discourse.vtk.org/t/cope-run-fourpaneviewer-demo-in-qtcreator-with-cmake/14771/4 "2024-12-05T17:19:29Z")

</div>

Hello,

Custom classes derived from VTK classes must often follow some formalities so they can be managed by the VTK framework.

Here is how I declared (`.h`) a class derived from `vtkInteractorStyleTrackballCamera`:

```cpp
#include <vtkObjectFactory.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkSmartPointer.h>
#include ...
#include ...

class myMouseInteractor : public vtkInteractorStyleTrackballCamera
{
public:
    static myMouseInteractor* New();
    vtkTypeMacro(myMouseInteractor, vtkInteractorStyleTrackballCamera)

    virtual void OnLeftButtonDown();

    virtual void OnLeftButtonUp();

    virtual void ...;

    virtual void ...;
...
};

```

And here is how I defined (`.cpp`) it:

```cpp
#include "mymouseinteractor.h"

#include ...
#include ...

// Implementation of the New() function for this class.
vtkStandardNewMacro(myMouseInteractor);

void myMouseInteractor::OnLeftButtonDown()
{ ...
}

void ...

...

```
