Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    qprocess qt 5.4 qfile qapplication
    4
    5
    1715
    Loading More Posts
    • 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
      Tusharh last edited by

      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 Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion last edited by

        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

        kshegunov the_ 2 Replies Last reply Reply Quote 0
        • kshegunov
          kshegunov Moderators @jsulm last edited by

          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 Reply Quote 0
          • the_
            the_ @jsulm last edited by

            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 --

            kshegunov 1 Reply Last reply Reply Quote 0
            • kshegunov
              kshegunov Moderators @the_ last edited by

              @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 Reply Quote 0
              • First post
                Last post