0

After reading this question I noticed - despite the initial question - the solution provided works only for remote files unless you have a webserver.

Instead I'm looking for a solution (that doesn't use Node.js) to "tail -f" a local file (on the same machine where the script runs) in order to read its changes. The script runs in a QML item, so no browsers nor webservers are involved.

The file might be updated quite quickly: i.e. several times per second, but with few chars at time only.

I'm able to read the file's content using an XMLHttpRequest but it seems it doesn't fit for my purpose.

UPDATE

After the downvote and the closing request I try to explain in other words.

I'm working on a commercial device that offers a loader for QML objects only. I cannot write C++ applications, there's no compilers, etc... Into /tmp folder there's a file that is continuously updated by a bash script. In my QML object I need to parse each line as soon as it is appended. The Qt version is 4.x and QtQuick is 1.1.

So I'm asking a way to achieve this goal with these constraints.

Mark
  • 4,338
  • 7
  • 58
  • 120
  • 1
    You said "a pure JavaScript way" but (a) XMLHttpRequest isn't "pure" JavaScript and (b) "pure" JavaScript has no input/output features at all, it depends entirely on the host environment to provide an API. – Quentin Nov 12 '18 at 08:13
  • It's written in the question: it's a QML object. Sorry for the misleading words, I will correct them. I mean without Node.js. – Mark Nov 12 '18 at 08:14
  • I know practically nothing of QML but a poke at the documentation says you should read the file from the main language for your app and then expose it to JS via a [property binding and/or signal handler](http://doc.qt.io/qt-5/qtqml-javascript-expressions.html). – Quentin Nov 12 '18 at 08:18
  • @Quentin yes, that's the standard way and I'm doing it daily. This time I *cannot* use a backend C++ application. Hence I asked how to do this in JS only. – Mark Nov 12 '18 at 08:26
  • "JavaScript has no input/output features at all, it depends entirely on the host environment to provide an API." – Quentin Nov 12 '18 at 08:27
  • If that's the answer, please don't comment and create an answer. – Mark Nov 12 '18 at 08:28
  • 1
    ECMAScript is the underlying language for JavaScript (typically written as "javascript" to mean implementations that support a DOM and i/o). Both require a host environment. ECMAScript has zero i/o, javascript has i/o depending on the implementation (e.g. various browsers, node, etc. see [*List of ECMAScript implementations*](https://en.wikipedia.org/wiki/List_of_ECMAScript_engines)). – RobG Nov 12 '18 at 08:36
  • Simply put, in a web browser, using javascript alone, you can't perform actions on local files as it would be a huge security risk. This answer of mine shows somewhat what can be done when it comes to file access/read: https://stackoverflow.com/questions/22031719/read-csv-file-with-javascript-into-a-key-value-pair-array/22033170#22033170 – Asons Nov 12 '18 at 09:39

0 Answers0