need to run only one instance of application
Hello,
before I worked with this delphi code:
Code:
function FileInstanceCheck(var mutex : THandle):boolean;
var
mutexName : array [0..7] of char;
begin
Result:=false;
StrPCopy(mutexName ,'anyname');
mutex := openmutex ( MUTEX_ALL_ACCESS, False, mutexName ) ;
If ((mutex <> 0) ) then
begin
MessageBeep($FFFFFFFF);
//MyMsgDialog('The application is already running.');
exit;
end;
mutex := createmutex ( nil , true, mutexName);
Result:=true;
end;
now, I look forward to a straightforward Qt code.
regards
navid
Re: need to run only one instance of application
Re: need to run only one instance of application
thanks, i will try new open source one
Re: need to run only one instance of application
Quote:
Originally Posted by
navid
please provide me with a free code
Respected Sir,
Would you like to have the code with a double scoop of choco chips icecream?
Re: need to run only one instance of application
Quote:
Originally Posted by
navid
thanks, i will try new open source one
http://qt.nokia.com/products/appdev/...leapplication/
Re: need to run only one instance of application
There is another possibility to do what you want:
Quote:
QLocalSocket socket;
socket.connectToServer(serverName);
if (socket.waitForConnected(500)) return;
m_localServer = new QLocalServer(this);
connect(m_localServer, SIGNAL(newConnection()), this, SLOT(newLocalSocketConnection()));
m_localServer->listen(serverName);
a) You create a QLocalSocket and connect to the server specified by the serverName;
b) Create a QLocalServer and listen for the connections;
c) before starting the application check how much connections you are listening already ... if there is at least one that means you have opened an application and you shouldn't let another one to open