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?
Forum Updated to NodeBB v4.3 + New Features

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.2k Views 2 Watching
  • 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 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
    • jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on 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

      kshegunovK the_T 2 Replies Last reply
      0
      • jsulmJ jsulm

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

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on 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
        • jsulmJ jsulm

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

          the_T Offline
          the_T Offline
          the_
          wrote on 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 --

          kshegunovK 1 Reply Last reply
          0
          • the_T the_

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

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on 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

            • Login

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