int main(int argc, char *argv[]){ QApplication app(argc, argv); QSharedMemory sharedMemory("appname"); if (!(sharedMemory.create(1) && sharedMemory.error() != QSharedMemory::AlreadyExists)) { exit(1); } ....}
bool MyApp::StopSecondInstance(const char * appTitle){ mMutex = ::CreateMutex(NULL, TRUE, mCaption); if (GetLastError() != ERROR_ALREADY_EXISTS) return false;// now returned value is a handle to other creator thus it should not be deleted, set it 0 mMutex = 0; // activate previous instance HWND wnd = FindWindow(mFrameClass, appTitle); if (wnd) { if (IsIconic(wnd)) ShowWindow(wnd, SW_RESTORE); SetForegroundWindow(wnd); } return true;}