QProcess: Destroyed while process (“F:\\UPrecise1.5\\UPrecise.exe“) is still running.

  1. 出错原因:

QProcess 执行start()后没有进行正常close(),所以在执行析构函数的时候就会报这个错;并不一定向网上说的创建指针等等。。

  1. 代码分析:

UPreciseWindow::UPreciseWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::UPreciseWindow),m_pProcess(NULL)
{
    ui->setupUi(this);
    m_pProcess = new QProcess(this);
    connect(m_pProcess, &QProcess::started, this, &UPreciseWindow::on_processStarted);
    //查找程序是否已经运行
    m_pProcess->waitForFinished(); //等待命令执行结束
    QString cmd="F:/UPrecise1.5/UPrecise.exe";
    m_pProcess->start(cmd);
    this->setWindowIcon(QIcon(":/new/resources/logo.png"));
}

UPreciseWindow::~UPreciseWindow()
{
    delete ui;
    m_pProcess->close();
    delete m_pProcess;
    m_pProcess=nullptr;
}

出错的原因就是析构函数中没有把QProcess的对象进行关闭,m_pProcess->close();

你可能感兴趣的:(QT,ui)