[Qt-interest] No POSIX Signals in Windows; How To Capture Program Termination

BRM bm_witness at yahoo.com
Tue Nov 23 20:05:37 CET 2010


----- Original Message ----

> From: William Gordon Rutherdale (rutherw) <rutherw at cisco.com>
> I have written a program using QCoreApplication that I want to  work
> portably across both Linux and Windows.
> 
> I added a feature to  print information such as statistics when the
> program terminates.  I got  this working in Linux by creating a handler
> for SIGINT/SIGTERM/SIGHUP that  posts an event.
> 
> Now, when I moved the source code to my Qt installation  in Windows, I
> couldn't get it to compile.  Qt sits on top of mingw,  which apparently
> doesn't support POSIX process semantics.  So the  compile-time error I
> got right away was that SIGHUP is an undefined  symbol.

While Windows purportedly does support POSIX, it doesn't really do so reliably.
Microsoft has even recommended removing the 'posix.dll' from Windows as part of 
securing the platform.
(Ironic considering how buggy the Win32 API is.) The only real issue with the 
posix.dll is that it was not
written for performance as Microsoft wanted people to use it as migration to 
doing things in Win32 only.
That said - you just can't rely on the posix.dll existing on a Windows platform.
 
> My question:  How can I write Qt code that detects imminent  shutdown in
> a similar fashion in Windows?

QCoreApplication has an aboutToQuit() signal. I would suggest using that 
directly if can.
If you can't b/c something isn't using Qt, then capture that signal and generate 
a Windows Event in response to notify that other part.

HTH,

Ben



More information about the Qt-interest-old mailing list