在我的这篇文章中使Qt程序只运行一个实例,通过QSharedMemory来实现进程间通讯,使用这种方式来是Qt程序只运行一个实例。有一天测试部的MM告诉我,她在测试的时候,程序crash掉了,再次运行程序,程序不能继续运行。
程序不能运行,显然是共享内存没有释放引起的,但是程序crash后为什么共享内存不能释放呢?于是打开Qt助手看到QSharedMemory是这样解释的:
Unix: QSharedMemory "owns" the shared memory segment. When the last
thread or process that has an instance of QSharedMemory attached to a
particular shared memory segment detaches from the segment by destroying
its instance of QSharedMemory, the Unix kernel release the shared
memory segment. But if that last thread or process crashes without
running the QSharedMemory destructor, the shared memory segment survives
the crash.
怎么可以这样?555…看来Nokia提供的QtSingleApplicationsolution的方法还是蛮好的。真是杯具丫,只好换
QtSingleApplication,下面就介绍一下我把QSingleApplication整合到自己的应用程序中去的方法一:
1.首先从的网站把Qt