# I want to call api on close event of mainwindow

**URL:** <https://discourse.slicer.org/t/i-want-to-call-api-on-close-event-of-mainwindow/30387>\
**Category:** Development\
**Created:** [July 4, 2023, 9:23am UTC](https://discourse.slicer.org/t/i-want-to-call-api-on-close-event-of-mainwindow/30387 "2023-07-04T09:23:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ssv/32/15085_2.png) [@ssv](https://discourse.slicer.org/u/ssv)\
**Post date:** [July 4, 2023, 9:23am UTC](https://discourse.slicer.org/t/i-want-to-call-api-on-close-event-of-mainwindow/30387/1 "2023-07-04T09:23:12Z")

</div>

What i want is if multiple instance is opened only the last instance will call the delete machine api , right now what happen is if i closr the app it get the count of running instance in memory that will give me wrong count if recently last app closed is still in memory

void qSlicerAppMainWindow::closeEvent(QCloseEvent\* event)  
{  
Q\_D(qSlicerAppMainWindow);

```
// This is necessary because of a Qt bug on MacOS.
// (https://bugreports.qt.io/browse/QTBUG-43344).
// This flag prevents a second close event to be handled.
if (d->IsClosing)
{
    event->ignore();
    return;
}
d->IsClosing = true;

if (d->confirmCloseApplication())
{
    // Proceed with closing the application

    // Exit current module to leave it a chance to change the UI (e.g. layout)
    // before writing settings.
    d->ModuleSelectorToolBar->selectModule("");

    this->saveGUIState();
    event->accept();

    //delete api call based on running instance
    QTimer::singleShot(0, qApp, SLOT(closeAllWindows()));
    
}
else
{
    // Request is cancelled, application will not be closed
    event->ignore();
    d->IsClosing = false;
}

```

} can anyone tell me how i can achieve this ?

---

<div class="post-metadata">

**Author:** ![ssv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ssv/32/15085_2.png) [@ssv](https://discourse.slicer.org/u/ssv)\
**Post date:** [July 5, 2023, 10:18am UTC](https://discourse.slicer.org/t/i-want-to-call-api-on-close-event-of-mainwindow/30387/2 "2023-07-05T10:18:31Z")

</div>

This was solved usin QSettings
