Andrea993
Andrea993

Reputation: 693

Sync files with sqlite database qt c++

I have many directories that I should sync with a sqlite db. The database should ever store the files content in these directories. To do this I've made a thread (lowest priority) that continuously looks for changes in the directories. However this thread uses 100% of cpu of one core. Is there a better way to sync files? Maybe a listener that emits a signal when a file will be created or removed?

Thanks, Regards Andrea

Upvotes: 1

Views: 592

Answers (1)

Matthias
Matthias

Reputation: 563

You can use QFileSystemWatcher.

From Qt Docs:

The QFileSystemWatcher class provides an interface for monitoring files and directories for modifications. QFileSystemWatcher monitors the file system for changes to files and directories by watching a list of specified paths. The fileChanged() signal is emitted when a file has been modified, renamed or removed from disk. Similarly, the directoryChanged() signal is emitted when a directory or its contents is modified or removed. Note that QFileSystemWatcher stops monitoring files once they have been renamed or removed from disk, and directories once they have been removed from disk.

Upvotes: 3

Related Questions