Qt avoids the warning "QProcess: destroyed while the process is still running

The simplest code:

void test
{
    QProcess p;
    p.start("sleep 10");
    p.waitForBytesWritten();
    p.waitForFinished(1);
}

Of course, the process cannot be completed before the end of the function, therefore a warning message is displayed:

 QProcess: Destroyed while process ("sleep") is still running.

I want this message not to be displayed - I have to kill this process myself before the end of the function, but I cannot find how to do it correctly: p. ~ QProcess (), p.terminate (), p.kill () cannot help me.

NOTE. I do not want to wait for the process to complete, just kill it when it starts.

+4
source share
1 answer

. , , , . "kill" , SIGKILL Unix , , .

, - :

main.cpp

#include <QProcess>

int main()
{
    QProcess p;
    p.start("sleep 10");
    p.waitForBytesWritten();
    if (!p.waitForFinished(1)) {
        p.kill();
        p.waitForFinished(1);
    }
    return 0;
}

main.pro

TEMPLATE = app
TARGET = main
QT = core
SOURCES += main.cpp
+6

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


All Articles