Results 1 to 8 of 8

Thread: How to not open the application second time if it is already running?

  1. #1
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default How to not open the application second time if it is already running?

    Hi ,I am using QT4.4 open source ,I have problem that If I click on my application second time, I get two same applications running at the same time. I tried this as shown below .
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. QFile lockFile("E:\\lockFile.lock");
    5. if (lockFile.isOpen())
    6. {
    7. QMessageBox::about(0, "Attention", "The app is already running");
    8. exit(1);
    9. }
    10. lockFile.open(QFile::WriteOnly);
    11. lpsu_application lp;
    12. lp.show();
    13. return a.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    But it is not working.I think the first application creates the file but it does not "hold" it and the next one does not see that the file is open.
    So help me to solve this problem with out using QtSingleApplication() class.

    With Regards,
    Sudheeer

  2. #2
    Join Date
    Oct 2008
    Posts
    70
    Thanks
    1
    Thanked 9 Times in 9 Posts

    Default Re: How to not open the application second time if it is already running?

    You can use followng for that:

    QtSingleApplication //Commercial
    SingleApplication //LGPL

  3. #3
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to not open the application second time if it is already running?

    Hi ,thanks for the quick reply.I have opened the link SingleApplication and dowloaded the total file.I go through it and find that it is useful to me.But one thing ,I don't no how to integrate this class with QT.
    So help me or suggest me to solve the problem.

    With Regards,

    Sudheer.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to not open the application second time if it is already running?

    To solve look at examples in SingleApplication package :
    Qt Code:
    1. QApplication app(argc, argv);
    2. app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
    3. // below is the magic code
    4. SingleApplication instance("TrivialExample", &app);
    5. if(instance.isRunning())
    6. {
    7. QString message = "Hello! Did You hear other Trivial Example instance? :)\n"
    8. "PID: " + QString::number(app.applicationPid());
    9. if(instance.sendMessage(message))
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to not open the application second time if it is already running?

    HI thanks for your kind reply.Actually my question is about how to integrate SingleApplication
    package with my QT4.4.0.
    So hlep me to solve this.

    With Regards,
    Sudheer.

  6. #6
    Join Date
    Oct 2008
    Posts
    70
    Thanks
    1
    Thanked 9 Times in 9 Posts

    Default Re: How to not open the application second time if it is already running?

    What's problem do you have with SingleApplication and QT4.4.0? Build errors or so?

  7. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to not open the application second time if it is already running?

    Quote Originally Posted by sudheer168 View Post
    Actually my question is about how to integrate SingleApplication
    package with my QT4.4.0.
    You must build library with SingleApplication package and link them with in Your's project. All is described in SingleApplication package docs.

  8. #8
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: How to not open the application second time if it is already running?

    Hi Lesiok,thanks for your kind reply.I will refer the docs and try it.

    Thanks and With Regards,
    Sudheer.

Similar Threads

  1. How open my application in other PCs without Qt?
    By Colx007 in forum Installation and Deployment
    Replies: 1
    Last Post: 2nd June 2008, 15:34
  2. Knowing if application is running
    By mourad in forum Qt Programming
    Replies: 1
    Last Post: 15th May 2008, 10:47
  3. Replies: 10
    Last Post: 10th March 2008, 12:28
  4. Replies: 10
    Last Post: 11th June 2007, 09:18
  5. How to open IGES files in Qt Application?
    By Shuchi Agrawal in forum Newbie
    Replies: 1
    Last Post: 21st February 2007, 01:06

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.