QProcess unknown error

前端 未结 1 1732
谎友^
谎友^ 2021-01-25 18:13

I got strange problem. QProcess just not working!

And error is unknown.

I got global var in header

QProcess *importModule;

An I

1条回答
  •  醉梦人生
    2021-01-25 19:05

    startDetached() is a static method and doesn't operate on importModule at all. It starts a process and then stops caring. Thus the error()/errorState() in importModule has nothing to do with the startDetached() call. What you want is start(). However, as QProcess is asynchronous, nothing will have happened yet immediately after start() returns. You must connect to the started(), error() and finished() signals to learn about the result.

    connect(importModule, SIGNAL(started()), this, SLOT(importModuleStarted()));
    connect(importModule, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(importModuleFinished(int, QProcess::ExitStatus)));
    CONNECT(importModule, SIGNAL(error(QProcess::ProcessError)), this, SLOT(importModuleError(QProcess::ProcessError)));
    importModule->start(QStringLiteral("importdb_module"), QStringList());
    

    Alternatively you can use the blocking wait functions:

    importModule->start(QStringLiteral("importdb_module"), QStringList());
    importModule->waitForStarted(); // waits until starting is completed
    importModule->waitForFinished(); // waits until the process is finished
    

    However, I strongly advise against using them in the main thread, as they block the UI then.

    0 讨论(0)
提交回复
热议问题