Unsolved ifstream crashes ui?
-
@timmie124 said:
so do I just need to put this code into another thread
That would be the easiest solution, yes. But you could also use a timer and look for new lines in the file every few milliseconds.
-
@Wieland I'll give it a shot thank you!
-
@timmie124 :-)
-
Mayby just
QApplication::processEvents()
? -
@michelson Yeah but then usage on one CPU core will stay at 100%.
-
Hi,
To add to @Wieland the QSocketNotifier class might be of interest for your use case.
-
I'd suggest QFileSystemWatcher too.
-
I'm with @SGaist,
QSocketNotifier
is appropriate for such things.QFileSystemWatcher
will watch for changes in attributes or directory structure, but I don't believe it actually notifies on content changes, but I might be wrong. -
@kshegunov said:
QFileSystemWatcher will watch for changes in attributes or directory structure, but I don't believe it actually notifies on content changes, but I might be wrong.
QFileSystemWatcher::fileChanged says:
This signal is emitted when the file at the specified path is modified, renamed or removed from disk.
It does detect file content changes on Windows (using FindFirstChangeNotification and friends) and on Linux (using inotify). It also has OSX and BSD implementations too, but I haven't looked into how they work.
QSocketNotifier
might be the better option, but I'd certainly consider both. It would be an interesting exercise to put together a minimal example of both options to compare their subtleties :)Cheers.
-
It does detect file content changes on Windows (using FindFirstChangeNotification and friends)
Well, MSDN doesn't mention a notification for the file being written as far as I could see, beside perhaps the size change or the last write time attribute. I don't know how responsive those are, but I suppose
QFileSystemWatcher
is a fair try.It would be an interesting exercise to put together a minimal example of both options to compare their subtleties
Indeed.