Results 1 to 6 of 6

Thread: need to run only one instance of application

  1. #1
    Join Date
    Oct 2009
    Posts
    90
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default need to run only one instance of application

    Hello,

    before I worked with this delphi code:

    Qt Code:
    1. function FileInstanceCheck(var mutex : THandle):boolean;
    2. var
    3. mutexName : array [0..7] of char;
    4. begin
    5. Result:=false;
    6. StrPCopy(mutexName ,'anyname');
    7. mutex := openmutex ( MUTEX_ALL_ACCESS, False, mutexName ) ;
    8. If ((mutex <> 0) ) then
    9. begin
    10. MessageBeep($FFFFFFFF);
    11. //MyMsgDialog('The application is already running.');
    12. exit;
    13. end;
    14. mutex := createmutex ( nil , true, mutexName);
    15. Result:=true;
    16. end;
    To copy to clipboard, switch view to plain text mode 

    now, I look forward to a straightforward Qt code.

    regards
    navid

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: need to run only one instance of application


  3. #3
    Join Date
    Oct 2009
    Posts
    90
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: need to run only one instance of application

    thanks, i will try new open source one

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: need to run only one instance of application

    Quote Originally Posted by navid View Post
    please provide me with a free code
    Respected Sir,
    Would you like to have the code with a double scoop of choco chips icecream?

  5. #5
    Join Date
    Aug 2009
    Posts
    52
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: need to run only one instance of application

    Quote Originally Posted by navid View Post
    thanks, i will try new open source one
    http://qt.nokia.com/products/appdev/...leapplication/

  6. #6
    Join Date
    Dec 2009
    Location
    Romania, Iasi
    Posts
    18
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: need to run only one instance of application

    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

Similar Threads

  1. Single Application Instance
    By BadKnees in forum Qt Programming
    Replies: 8
    Last Post: 4th November 2014, 14:57
  2. only one instance of an application in windows
    By jorgeact in forum Qt Programming
    Replies: 2
    Last Post: 26th October 2008, 10:41
  3. Replies: 5
    Last Post: 9th June 2008, 11:21
  4. Only let one instance of the application run
    By chrisdsimpson in forum Newbie
    Replies: 1
    Last Post: 9th April 2008, 21:30
  5. Replies: 5
    Last Post: 16th January 2006, 05:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.