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. Is there any way to know if a particular file is open/in use/locked by another application/process?
QtWS25 Last Chance

Is there any way to know if a particular file is open/in use/locked by another application/process?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qprocessqt 5.4qfileqapplication
5 Posts 4 Posters 2.1k 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.
  • T Offline
    T Offline
    Tusharh
    wrote on 18 Feb 2016, 13:26 last edited by
    #1

    I want to know if a file is in use in another application. I tried to look around QFile, QProcess but there seems no way to find out. I am trying to do some text file manipulation which is used constantly by many applications. Before doing anything I would like to know if it's in use/open/locked by other app.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 18 Feb 2016, 13:49 last edited by
      #2

      Do you want to lock the file before using it?
      In this case you can use http://doc.qt.io/qt-5/qlockfile.html

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

      K T 2 Replies Last reply 18 Feb 2016, 13:52
      0
      • J jsulm
        18 Feb 2016, 13:49

        Do you want to lock the file before using it?
        In this case you can use http://doc.qt.io/qt-5/qlockfile.html

        K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 18 Feb 2016, 13:52 last edited by
        #3

        To add to @jsulm's excellent suggestion, you should tell what OS you're intending on using this on, and what are these "many applications". Are these applications written by you, are they using Qt?

        Kind regards.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        0
        • J jsulm
          18 Feb 2016, 13:49

          Do you want to lock the file before using it?
          In this case you can use http://doc.qt.io/qt-5/qlockfile.html

          T Offline
          T Offline
          the_
          wrote on 18 Feb 2016, 13:54 last edited by
          #4

          As long as the other (external) application / process locks the file you want to access, the solution @jsulm suggested will work.

          -- No support in PM --

          K 1 Reply Last reply 18 Feb 2016, 14:15
          0
          • T the_
            18 Feb 2016, 13:54

            As long as the other (external) application / process locks the file you want to access, the solution @jsulm suggested will work.

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 18 Feb 2016, 14:15 last edited by
            #5

            @the_

            will work

            Such a strong word ... it depends on the advisory locking mechanism used and most linux-es will support more than one. As duly noted in the documentation it's only guaranteed to work if the same scheme is used across all processes:

            Serialization is only guaranteed if all processes that access the shared resource use QLockFile, with the same file path.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0

            2/5

            18 Feb 2016, 13:49

            • Login

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