How to detect "Close all windows" event in qt application
-
Hello,
I have multiple instances of qt application opened.
Now I close all the instances "Close all windows" using mouse right in task bar(windows 10).
How will I detect the "Close all windows" event ?
or
How to differentiate if "CloseEvent" call is for single instance or multiple instances ?Thanks in advance.
-
Afaik this is not possible - I would guess windows simply sends a WM_CLOSE to every application and does not distinguish if this is done in a batch or as single event. Also don't see a need for this.
-
Afaik this is not possible - I would guess windows simply sends a WM_CLOSE to every application and does not distinguish if this is done in a batch or as single event. Also don't see a need for this.
@Christian-Ehrlicher
Thanks for your reply.
I have a use case where I need to check if I am closing single instance or multiple instances.
Based on this I need to perform certain actions differently.
So it would be very helpful for me, if there is a way to differentiate this. -
You should ask in a windows programmer forum if there is a way but I doubt - WM_CLOSE has no parameters as you can see.
-
Windows just sends a message to a window in each of the processes. A process doesn't know about messages sent to other processes. It would be difficult considering user privileges etc. Would be a security risk too. Another instance of the same app is not a special case, it's just another process. Two users can run the same app and then what? Wouldn't be a good idea to inform other processes what messages are sent to yours.
Also, even if such "multicast" message existed there's another problem - those processes probably get the message in some sort of a loop and there's a time between a message is sent, received and processed. By the time the last process gets it the first one could be already gone or some processes could ignore/reject it. There' no automatic way for you to know that.
If you want this sort of communication you need to implement it explicitly yourself. For example you could use something like QSharedMemory and bump some sort of a shared counter or add yourself to a list of processes that received the close message. Be very careful though and don't assume these other processes are still alive while you're processing the message you got. It's not exactly the same as getting an information that "close all" was pressed, but could help you to handle scenarios like figuring out if your process is the last man standing.