On Wednesday, 16 September 2015 at 16:30:46 UTC, Mike McKee wrote:
This really shows the beauty and simplicity of the D language compared to C++. Check this out in Qt/C++:

http://stackoverflow.com/questions/32593463/spawn-async-qprocess-from-dynamic-library-peek-output-until-done

...see how much nicer the D version is here that Ali did, versus the Qt/C++ technique.

Here is an alternative Qt sample to handle the output of a process line by line and to get notified when it finishes:


#include <QCoreApplication>
#include <QProcess>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QProcess scanner;

    QObject::connect(&scanner, &QProcess::readyRead, [&] {
        while (!scanner.atEnd()) {
            auto line = scanner.readLine();
            // process line
        }
    });

    // select the QProcess::finished(int) overload
    void (QProcess::*finishedSignal)(int) = &QProcess::finished;

    QObject::connect(&scanner, finishedSignal, [] (int) {
       // proces finished
       QCoreApplication::quit();
    });

    scanner.start("avscanner");

    return a.exec();
}


Reply via email to