Important: Please read the Qt Code of Conduct -

InnoSetup / Windows Restart Manager / Native Event Filter problem.

  • I am using InnoSetup as the installer for my QT application. InnoSetup tries to close my application if it is running when to try to install a new version. According to the InnoSetup docs, this is done using the windows RestartManager service.

    My application is a small application that sits in the system tray. When InnoSetup tries to terminate the application, the system tray icon disappears (at least it does when I move my mouse over it), but the process is still running in Task Manager and never terminates.

    My app starts with just the system tray icon showing. If you double click it it opens a log window, or right clicking it shows a menu. If you do either of these things before running the installer, the application exits fine. If the app has just been run up and not interacted with, then it does not exit.

    I tried installing a native event filter at the application level to capture WM_QUERYENDSESSION and WM_ENDSESSION (with lParam ENDSESSION_CLOSEAPP). Again, if the app has been interacted with, my event filter code executes. If there has been no interaction with the app, the event filter code never gets run.

    If you want to take a look at my application code it is available at

    EDIT: sorry I forgot to mention, I am using QT 5.1.1 compiled by me for VS2008 (32-bit).


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    WM_QUERYENDSESSION and WM_ENDSESSION are now again handled starting Qt 5.2, so you should get the proper functionality with this version

  • That's great news thanks.

    However, I am still interested to know why my native event filter does not get fired unless I have interacted with the application?


  • Lifetime Qt Champion

    Good question, can you show the filter code ?

  • Here's my modified main.cpp that installs an event filter.

    Copyright 2011-2013 Alan Davies.

    This file is part of Rock Scrobbler.

    Rock Scrobbler is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    Rock Scrobbler is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with Rock Scrobbler.  If not, see <>.

    In addition, as a special exception, the copyright holders give
    permission to link the code of portions of this program with the
    OpenSSL library under certain conditions as described in each
    individual source file, and distribute linked combinations
    including the two.

    You must obey the GNU General Public License in all respects
    for all of the code used other than OpenSSL. If you modify
    file(s) with this exception, you may extend this exception to your
    version of the file(s), but you are not obligated to do so. If you
    do not wish to do so, delete this exception statement from your
    version. If you delete this exception statement from all source
    files in the program, then also delete it here.

    #include <QAbstractNativeEventFilter>
    #include <QFileInfo>
    #include <QSharedMemory>
    #include <QtWidgets/QApplication>

    #include <QtPlugin>

    #include "LogWindow.h"

    #include <windows.h>

    #if (defined QT_STATICPLUGIN)

    #define SHARED_MEMORY_UUID "928fe311-dbb1-43e3-b659-8fa44ac50fcf"

    class MyEventFilter : public QAbstractNativeEventFilter
    virtual bool nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pResult);

    bool MyEventFilter::nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pResult)
    const MSG &msg = *static_cast<MSG *>(pMessage);

    switch (msg.message)
    if (msg.lParam == ENDSESSION_CLOSEAPP)
    *pResult = 1;
    return true;


    return false;

    int main(int argc, char *argv[])
    // Only allow one instance by creating a named shared memory segment.
    // If the create() call fails because the segment exists, then exit.
    QSharedMemory sharedMem(SHARED_MEMORY_UUID);
    if (!sharedMem.create(1) && (sharedMem.error() == QSharedMemory::AlreadyExists))

    #if (!defined QT_DEBUG)
    // Get path of current executable
    const QString executablePath = QFileInfo(LogWindow::getCurrentExecutablePath()).path();

    // Set plugin path to only be the path of the running executable
    // This means that an installed version won't pick up plugins from the QT SDK

    MyEventFilter * const pMyEventFilter = new MyEventFilter;

    QApplication a(argc, argv);

    LogWindow w;

    // Don't call - start hidden.

    return a.exec();

  • This post is deleted!

Log in to reply