开发者

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

开发者 https://www.devze.com 2023-02-10 15:32 出处:网络
I have the following scenario: QProcess*p; // later p->start(); //later开发者_C百科 p->terminate(); // there might be unread data in stdout

I have the following scenario:

QProcess*p;
// later 
p->start();
//later开发者_C百科
p->terminate(); // there might be unread data in stdout
//later
p->start();

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


Okay, I've checked the sources. The QProcess::start() method explicitly clears both output buffers, so it should be okay, 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 it's a bad style to reuse the same object, though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号