Uploaded image for project: 'Qt Solutions'
  1. Qt Solutions
  2. QTSOLBUG-139

QtSingleApplication doesn't lock on construction of object

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • Some Release
    • Single Application
    • 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())

      { qDebug() << "Shutdown sending shutdown message to other instance"; app.sendMessage("shutdown", 30000); }

      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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            dagenaisj Jeff Dagenais
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes