gpt4 book ai didi

c++ - Qt避免警告QProcess : destroyed while process still running (Assistant)

转载 作者:行者123 更新时间:2023-11-28 06:34:18 30 4
gpt4 key购买 nike

我正在运行一个启动进程的 Qt 应用程序。 (助手,从主应用启动)。

当我关闭应用程序时,我收到警告

QProcess:进程仍在运行时被销毁。

我怎样才能摆脱它?

我看到了这个similar question并试图杀死……什么也没发生。

question似乎在说也许我应该添加 waitForFinished()...应用程序关闭时帮助不会关闭。

Help::Help():m_helpProcess(0) {}

Help::~Help()
{
if (m_helpProcess) {
m_helpProcess.waitForFinished(); // help stays open after app closes
m_helpProcess->kill(); // added with no effect
delete m_helpProcess;
}
}

bool Help::start()
{
if (!m_helpProcess)
process = new QProcess();
QStringList args;
args << QLatin1String("-collectionFile")
<< QLatin1String("mycollection.qhc");
process->start(QLatin1String("Assistant.app"), args);
if (!process->waitForStarted())
return;
}

最佳答案

使用 close() 重写析构函数应该就足够了:

Closes all communication with the process and kills it. After calling this function, QProcess will no longer emit readyRead(), and data can no longer be read or written.

Help::~Help()
{
if (m_helpProcess) {
// m_helpProcess->waitForFinished(); // help stays open after app closes
m_helpProcess->close(); // close channels
delete m_helpProcess; // destructor actually kills the process
}
}

关于c++ - Qt避免警告QProcess : destroyed while process still running (Assistant),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27001143/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com