If I reuse the QProcess variable, can there be any remaining data in the stdout / stderr channels?

I have the following script:

QProcess*p;
// later 
p->start();
//later
p->terminate(); // there might be unread data in stdout
//later
p->start();

I read the stdout process. After I call p-> start () a second time, can there be more unread data left in the stdout buffers from the first p-> start ()? This will be a problem for me. Do I need to flush buffers or something else?

+3
source share
1 answer

Ok, I checked the sources. The QProcess :: start () method explicitly flushes both output buffers, so it should be fine, at least in this sense:

void QProcess::start(const QString &program, const QStringList &arguments, OpenMode mode)
{
    Q_D(QProcess);
    if (d->processState != NotRunning) {
        qWarning("QProcess::start: Process is already running");
        return;
    }

#if defined QPROCESS_DEBUG
    qDebug() << "QProcess::start(" << program << "," << arguments << "," << mode << ")";
#endif

    d->outputReadBuffer.clear();
    d->errorReadBuffer.clear();

I still think this is a bad style for reusing the same object.

+7
source

Source: https://habr.com/ru/post/1791652/


All Articles