Details
-
Bug
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
Some Release
-
None
-
2.6.35-19-generic #28-Ubuntu SMP Sun Aug 29 06:34:38 UTC 2010 x86_64 GNU/Linux
qtsingleapplication-2.6_1-opensource.tar.gz
Description
I had code that looked like this in my main:
int main(int argc, char* argv[])
{
QtSingleApplication app("my_unique_app", argc, argv);
QStringList cmdLineArgs = app.arguments();
if (cmdLineArgs.contains("shutdown"))
{
qDebug() << "Shutdown selected";
if(app.isRunning())
else
qDebug() << "Shutdown No other instance found.";
return 0;
}
...
}
Unfortunately, this doesn't work, because the second instance I start get false when calling app.isRunning(). I figured out why, it seems that calling "isRunning()" has the side effect of actually locking the QtLockedFile, and since my first instance didn't have the "isRunning()" check because the command line args didn't containt "shutdown", then the file is not locked.
If I had followed precisely the example I wouldn't have encountered the problem... and there is no mention in the documentation.
So either call QtLocalPeer::isClient() from it's constructor (to ensure lock) or explicitely mention that isRunning() should always be called, i.e. that it has the side-effect of actually declaring the first instance.