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 .
Code:
int main(int argc, char *argv[])
{
QFile lockFile
("E:\\lockFile.lock");
if (lockFile.isOpen())
{
QMessageBox::about(0,
"Attention",
"The app is already running");
exit(1);
}
lockFile.
open(QFile::WriteOnly);
lpsu_application lp;
lp.show();
return a.exec();
}
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
Re: How to not open the application second time if it is already running?
You can use followng for that:
QtSingleApplication //Commercial
SingleApplication //LGPL
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.
Re: How to not open the application second time if it is already running?
To solve look at examples in SingleApplication package :
Code:
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
// below is the magic code
SingleApplication instance("TrivialExample", &app);
if(instance.isRunning())
{
QString message
= "Hello! Did You hear other Trivial Example instance? :)\n" "PID: " + QString::number(app.
applicationPid());
if(instance.sendMessage(message))
return 0;
}
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.
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?
Re: How to not open the application second time if it is already running?
Quote:
Originally Posted by
sudheer168
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.
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.