0

I have a Qt application (A) that runs as a Windows system tray application.

I also have another Qt application (B) that launches/closes any executable.

If I try to close application (A) with its system tray context menu, everything works as expected (process is killed, system tray icon disappears).

However, if I try to close application (A) via application (B), the system tray icon of application (A) disappears, but its process remains running in the background. I have to force kill the process to get it to quit.

Application (B) uses QProcess to launch executables. When requested, it calls QProcess::terminate() to close the launched application.

There is no issue closing applications that actually have windows (forms). It is only this one windowless system tray application (A) that is having issues.

I have overridden the QWidget::closeEvent(...), which is never triggered/called.

How can I get the closeEvent(...) to be triggered in application (A)?

Qt documentation implies that the closeEvent is triggered by a window close request, which may be the problem since application (A) has no windows. Do I need to give application (A) a form and hide it?

  • 1
    provide a [mcve] – eyllanesc Sep 20 '18 at 20:34
  • Hi @tranqui341, we may need more information in order to help. Notice that what you see in the Windows system tray is a window and has a handle allocated to it (you can even use Spy++ to deep-dive its properties and messages). Also, when you application B calls _terminate()_, if your application A is not using a QApplication loop with exec() it will not close the process, only all top-level windows of the process. Please share more so we can help. – diogoslima Sep 20 '18 at 22:45

1 Answers1

0

Turns out a form is required to receive the closeEvent.

[closeEvent] is called with the given event when Qt receives a window close request for a top-level widget from the window system.

I added a form to application (A) and hid it.

setStyleSheet( "background: transparent;" );
setAttribute( Qt::WA_TranslucentBackground );

Now when application (B) sends the QProcess::terminate() the closeEvent is triggered and everything shuts down as expected!

Well, almost... One thing I didn't expect is that, even with the window hidden, it still had a taskbar button. To remove it, I added the following to the constructor:

setWindowFlags( Qt::SubWindow ); 
show();

Qt Hide Taskbar Item