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. [C++] How to check if a file is used by another process ?
Forum Updated to NodeBB v4.3 + New Features

[C++] How to check if a file is used by another process ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 2.9k 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.
  • J Offline
    J Offline
    Johan_R28
    wrote on last edited by Johan_R28
    #1
    This post is deleted!
    1 Reply Last reply
    0
    • miclandM Offline
      miclandM Offline
      micland
      wrote on last edited by
      #2

      Uhm, you say you want to read the file but in your code snippet you write the file...?

      AFAIR there is no native way to check whether a file is still opened or not. You can get notified about changes, but how shall the QFileSystemWatcher know that there will be no further changes in the future?

      J 1 Reply Last reply
      1
      • J Offline
        J Offline
        Johan_R28
        wrote on last edited by Johan_R28
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • miclandM micland

          Uhm, you say you want to read the file but in your code snippet you write the file...?

          AFAIR there is no native way to check whether a file is still opened or not. You can get notified about changes, but how shall the QFileSystemWatcher know that there will be no further changes in the future?

          J Offline
          J Offline
          Johan_R28
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • miclandM Offline
            miclandM Offline
            micland
            wrote on last edited by
            #5

            @Johan_R28
            I don't know if there is a native way to solve your problem but I think you should read all data and extend your buffer (or process the new data) when a modification was detected. There is no "fileFinallyChanged" signal.
            If you have both processes under control you could also try to sync them using a separate IPC (The writing process tells the reading process that the work is done) or by writing the data to a preliminary, temporary file that will be renamed after the file is complete so the reading process will not "see" while the generating is still in progress (just one of many possible ways - the best solution depends on your needs).

            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