简体   繁体   中英

How to check if Qt GUI application is already running (in Linux)?

I need to check if my Qt GUI application is already running in the current X session . That is, I want to forbid running several instances of it. But running several instances by different users or by the same user on another (ie remote) X server should be allowed.

How can this be done?

Qt has already a solution to single instance per user: QtSingleApplication . Check if this suits you.

Create a dotfile (say, ~/.yourapp-xsessionID) when launching the program, and delete it when exiting; it the file already exists (ie it's already running) print out an error message and exit.

For the problems with this approach, see Firefox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM