# vtkEventQtSlotConnect: Slot not being called

**URL:** https://discourse.vtk.org/t/vtkeventqtslotconnect-slot-not-being-called/6566
**Category:** Support
**Created:** [September 6, 2021, 6:10pm UTC](https://discourse.vtk.org/t/vtkeventqtslotconnect-slot-not-being-called/6566 "2021-09-06T18:10:19Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nicfel](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nicfel/32/3639_2.png) [@nicfel](https://discourse.vtk.org/u/nicfel)
#### Post date: [September 6, 2021, 6:10pm UTC](https://discourse.vtk.org/t/vtkeventqtslotconnect-slot-not-being-called/6566/1 "2021-09-06T18:10:19Z")

</div>

Hey there,

I am using Qt with vtk. I recently created a plot (_vkPlotPoints_ inside a _vtkChartXY_ inside a _vtkContextView_). Next I want to do something within my code when a user selects points within the plot. I found the vtkEventQtSlotConnect and an example for it. I tried to replicate that in my code but I can’t get it to work.

The header (I removed some unrelated code):

```auto
class Plot: public QObject {

        Q_OBJECT

    public:

        Plot();

        ~Plot() override = default;

    signals:

        void pointsSelected();

    private slots:

        // this should be executed when the right mouse button is released
        void receiveRightButtonEvent(vtkObject*, unsigned long eid, void *clientdata, void *calldata);

    private:

        void CreatePlot();

        // this extends QVTKOpenGLNativeWidget and stores vtkRenderViewBase. 
        // this is a helper to do initialization. I can store different types of views in here
        Scene::ViewScene mViewScene;

```

The constructor implementation (I also removed unrelated stuff here):

```auto
    Plot::Plot()
    : mViewScene()
    {

       // takes care of creating the plot
       CreatePlot();

        vtkNew<vtkEventQtSlotConnect> eventQtSlotConnect;
        eventQtSlotConnect->Connect(
                mViewScene.renderWindow()->GetInteractor(), vtkCommand::RightButtonPressEvent,
                this, SLOT(receiveRightButtonEvent(vtkObject*, unsigned long, void*, void*))
                );
    }

```

```auto
    void Plot::receiveRightButtonEvent(vtkObject*, unsigned long eid, void *clientdata, void *calldata) {
        std::cout << "yes" << std::endl;
    }

```

I expect “yes” to be printed but nothing is being printed. I assume that the problem is related to this part of the connect statement:

`mViewScene.renderWindow()->GetInteractor()`

because it is the only one that is different from the [example](https://kitware.github.io/vtk-examples/site/Cxx/Qt/EventQtSlotConnect/).

---

<div class="post-metadata">

### Author: ![nicfel](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nicfel/32/3639_2.png) [@nicfel](https://discourse.vtk.org/u/nicfel)
#### Post date: [September 8, 2021, 10:34am UTC](https://discourse.vtk.org/t/vtkeventqtslotconnect-slot-not-being-called/6566/2 "2021-09-08T10:34:09Z")

</div>

I solved it. Apparently you have to store the vtkEventQtSlotConnect object otherwise the signals will not be delivered.  
So basically this line is incorrect:

```auto
vtkNew<vtkEventQtSlotConnect> eventQtSlotConnect;

```

and should be changed to something that is stored permanently. For example a member variable of your class.
