Friday, July 4th 2008, 10:33pm UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Posts: 59

Location: Belarus/Germany

Occupation: Progr

1

Thursday, May 15th 2008, 11:57am

How to: App check if already one copy of this App is started

Hi All!

Can someone give me advice how to check in my App is one copy of this App already running or not..?!?

Thanks! [QT]

This post has been edited 1 times, last edit by "AcerExtensa" (May 15th 2008, 11:57am)

  • Go to the top of the page

2

Thursday, May 15th 2008, 12:11pm

RE: How to: App check if already one copy of this App is started

You can use QtSingleApplication class, but i think it is only in the commercial edition.
On MacOS you cannot launch the application several times.
On Window you need to create a mutex

You can use this in your main :

#ifdef Q_WS_WIN
HANDLE hMutex = NULL;
#endif
int code = -1;
try
{

#ifdef Q_WS_WIN
hMutex = CreateMutex (NULL,FALSE,L"Thenameoftheapllicationforexample");
if ( (hMutex == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS) )
{
CloseHandle(hMutex);
return -1;
}
#endif

// Your code
// ...


}
catch(...)
{
// Your code
}

#ifdef Q_WS_WIN
CloseHandle(hMutex);
#endif
return code;

}
  • Go to the top of the page

Posts: 59

Location: Belarus/Germany

Occupation: Progr

3

Thursday, May 15th 2008, 12:31pm

Thank you! That Works!
  • Go to the top of the page

Rate this thread