Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. check apps conflict

check apps conflict

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 6 Posters 568 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    s002wjh
    wrote on last edited by
    #1

    is there way to check if 2 identical qt app is running in the same directory?

    for example both of same qt apps are try to modify a single file, thus create a conflict, is there anyway to check this type conflict.

    ODБOïO jsulmJ J.HilkJ 3 Replies Last reply
    0
    • S s002wjh

      is there way to check if 2 identical qt app is running in the same directory?

      for example both of same qt apps are try to modify a single file, thus create a conflict, is there anyway to check this type conflict.

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      hi @s002wjh
      you can use lock file approach

      1 Reply Last reply
      2
      • S s002wjh

        is there way to check if 2 identical qt app is running in the same directory?

        for example both of same qt apps are try to modify a single file, thus create a conflict, is there anyway to check this type conflict.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @s002wjh On Linux you can use lsof command to list open files and filter the list by process id.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • S s002wjh

          is there way to check if 2 identical qt app is running in the same directory?

          for example both of same qt apps are try to modify a single file, thus create a conflict, is there anyway to check this type conflict.

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @s002wjh
          Qt has a QLockFile class
          https://doc.qt.io/qt-5/qlockfile.html

          But both Qt apps have to use it, from what I understand.


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          3
          • S Offline
            S Offline
            s002wjh
            wrote on last edited by
            #5

            can I lock one of the apps, so if the 2nd apps is running and access certain directory, it output an error

            JonBJ 1 Reply Last reply
            0
            • LematL Offline
              LematL Offline
              Lemat
              wrote on last edited by Lemat
              #6

              you could prevent second app to run by set a same QSharedMemory key to these.
              I had this problem.

              if it can helped, Place this code in the two applications (their main.cpp before app.exec ();):

              auto m_location=new QSharedMemory ();
              m_location->setKey(a_key);
              if (!memoadd->create (sizeof (int) )
              {
                m_location->attach ();
                m_location->detach ();
               if (!m_location->create (sizeof (int))) 
              {
                //exit(0); or what you want
              }
              

              Time to elevate.

              LematL 1 Reply Last reply
              1
              • LematL Lemat

                you could prevent second app to run by set a same QSharedMemory key to these.
                I had this problem.

                if it can helped, Place this code in the two applications (their main.cpp before app.exec ();):

                auto m_location=new QSharedMemory ();
                m_location->setKey(a_key);
                if (!memoadd->create (sizeof (int) )
                {
                  m_location->attach ();
                  m_location->detach ();
                 if (!m_location->create (sizeof (int))) 
                {
                  //exit(0); or what you want
                }
                
                LematL Offline
                LematL Offline
                Lemat
                wrote on last edited by
                #7

                @Lemat
                or you can use wmic on Windows or pgrep on macOS or linux to getted out running process's and check if an app name is in it.

                QProcess
                

                Time to elevate.

                1 Reply Last reply
                0
                • S s002wjh

                  can I lock one of the apps, so if the 2nd apps is running and access certain directory, it output an error

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @s002wjh said in check apps conflict:

                  is there way to check if 2 identical qt app is running in the same directory
                  can I lock one of the apps, so if the 2nd apps is running and access certain directory, it output an error

                  You're going to have to a bit more precise if you want a precise answer. What exactly does "running in the same directory" & "access certain directory" mean to you?

                  And are you saying your solution is allowed to change the code of both Qt apps?

                  Some of the proposed solutions here are trying to prevent a second instance of a Qt application from running. But I think you're saying it's OK to run two instances, what you want is only to control simultaneous file/directory access across the processes? Please clarify which kind of solution you are seeking.

                  1 Reply Last reply
                  2

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved