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 (i.e. remote) X server should be allowed.
我需要检查我的Qt GUI应用程序是否已在当前的X会话中运行。也就是说,我想禁止运行它的几个实例。但是应该允许不同用户或另一个(即远程)X服务器上的同一用户运行多个实例。
How can this be done?
如何才能做到这一点?
Thank you.
2 个解决方案
#1
Qt has already a solution to single instance per user: QtSingleApplication. Check if this suits you.
Qt已经为每个用户的单个实例提供了解决方案:QtSingleApplication。检查这是否适合你。
#2
Create a dotfile (say, ~/.yourapp-xsessionID) when launching the program, and delete it when exiting; it the file already exists (i.e. it's already running) print out an error message and exit.
启动程序时创建一个dotfile(比如〜/ .yourapp-xsessionID),并在退出时删除它;文件已存在(即它已经运行)打印出错误信息并退出。
For the problems with this approach, see Firefox.
有关此方法的问题,请参阅Firefox。
#1
Qt has already a solution to single instance per user: QtSingleApplication. Check if this suits you.
Qt已经为每个用户的单个实例提供了解决方案:QtSingleApplication。检查这是否适合你。
#2
Create a dotfile (say, ~/.yourapp-xsessionID) when launching the program, and delete it when exiting; it the file already exists (i.e. it's already running) print out an error message and exit.
启动程序时创建一个dotfile(比如〜/ .yourapp-xsessionID),并在退出时删除它;文件已存在(即它已经运行)打印出错误信息并退出。
For the problems with this approach, see Firefox.
有关此方法的问题,请参阅Firefox。