PDA

View Full Version : need to run only one instance of application



navid
24th December 2009, 07:32
Hello,

before I worked with this delphi 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

yogeshgokul
24th December 2009, 07:45
Please refer following link.
http://qt.nokia.com/products/appdev/add-on-products/catalog/3/Utilities/qtsingleapplication

navid
24th December 2009, 09:34
thanks, i will try new open source one

yogeshgokul
24th December 2009, 09:37
please provide me with a free code
Respected Sir,
Would you like to have the code with a double scoop of choco chips icecream?

dbzhang800
24th December 2009, 09:39
thanks, i will try new open source one
http://qt.nokia.com/products/appdev/add-on-products/catalog/4/Utilities/qtsingleapplication/

vcernobai
24th December 2009, 09:52
There is another possibility to do what you want:


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