# EventQtSlotConnect

VTKExamples/Cxx/Qt/EventQtSlotConnect

### Code

EventQtSlotConnect.cxx

    #include "EventQtSlotConnect.h"

    #include "vtkGenericOpenGLRenderWindow.h"
    #include <vtkNew.h>
    #include <vtkPolyDataMapper.h>
    #include <vtkRenderer.h>
    #include <vtkRenderWindow.h>
    #include <vtkSphereSource.h>
    #include <vtkEventQtSlotConnect.h>
    #include <vtkInteractorStyleTrackballActor.h>

    // Constructor
    EventQtSlotConnect::EventQtSlotConnect()
    {
      this->setupUi(this);
      vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;
      this->qvtkWidget->SetRenderWindow(renderWindow);

      vtkNew<vtkEventQtSlotConnect> slotConnector;
      this->Connections = slotConnector;

      // Sphere
      vtkNew<vtkSphereSource> sphereSource;
      sphereSource->Update();
      vtkNew<vtkPolyDataMapper> sphereMapper;
      sphereMapper->SetInputConnection(sphereSource->GetOutputPort());

      vtkNew<vtkActor> sphereActor;
      sphereActor->SetMapper(sphereMapper);

      // VTK Renderer
      vtkNew<vtkRenderer> renderer;
      renderer->AddActor(sphereActor);

      this->qvtkWidget->GetRenderWindow()->AddRenderer(renderer);

      this->Connections->Connect(this->qvtkWidget->GetRenderWindow()->GetInteractor(),
      vtkCommand::LeftButtonPressEvent,
      this,
      SLOT(slot_clicked(vtkObject*, unsigned long, void*, void*)));

    };

    void EventQtSlotConnect::slot_clicked(vtkObject*, unsigned long, void*, void*)
    {
      std::cout << "Clicked." << std::endl;
    }

### CMakeLists.txt

    cmake_minimum_required(VERSION 2.8)

    PROJECT(EventQtSlotConnect)

    find_package(VTK REQUIRED)
    include(${VTK_USE_FILE})

    add_executable(EventQtSlotConnect MACOSX_BUNDLE EventQtSlotConnect.cxx )

    target_link_libraries(EventQtSlotConnect ${VTK_LIBRARIES})

### Download and Build EventQtSlotConnect

Click here to download EventQtSlotConnect and its CMakeLists.txt file. Once the tarball EventQtSlotConnect.tar has been downloaded and extracted,

    cd EventQtSlotConnect/build

If VTK is installed:

    cmake ..

If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:

    cmake -DVTK_DIR:PATH=/home/me/vtk_build ..

Build the project:

    make

and run it:

    ./EventQtSlotConnect

WINDOWS USERS PLEASE NOTE: Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.