Qt进程自动终止

Qt进程自动终止,qt,Qt,点击按钮,需要启动两个流程(p和pr)。但不幸的是,我的第二个进程(pr)自动终止。永远不会调用函数extlan QString lancn; void MainWindow::on_lineEditPathSet(QString inputpath) { QString parameters = " " + settings.value("save_nmix").toString() + " " + settings.value("save_norm_method").toStri

点击按钮,需要启动两个流程(p和pr)。但不幸的是,我的第二个进程(pr)自动终止。永远不会调用函数extlan

QString lancn;
void MainWindow::on_lineEditPathSet(QString inputpath)
{ 

    QString parameters = " " + settings.value("save_nmix").toString() + " " + settings.value("save_norm_method").toString() + " " + settings.value("save_thresh_value").toString() + " " + settings.value("save_oos_thresh").toString() + " " + flag;
    QString cmd = "test.exe " + inputpath + parameters;

    if (p)
    {
      p->setEnvironment( QProcess::systemEnvironment() );
      p->setProcessChannelMode( QProcess::SeparateChannels );
      p->start(cmd);
      p->waitForStarted();
      connect( p, SIGNAL(readyReadStandardOutput()), this, SLOT(OutTable()) );
      connect( p, SIGNAL(readyReadStandardError()), this, SLOT(ErrConsole()));
    }

    QMessageBox msgBox(this);
    msgBox.setWindowTitle("Launching Testing Process");
    msgBox.setText("Testing process is being initialized.\n\nIt may take some time.\n\nPlease wait.");
    msgBox.setIcon(QMessageBox::Information);
    msgBox.exec();
    if(lang_method.compare("ConvoNet")==0)
    {
        QProcess pr;

        QStringList params;
        params.append("test.py");
        params.append(inputpath);
        pr.start("python", params);
        pr.waitForStarted();
        connect( &pr, SIGNAL(readyReadStandardOutput()), this, SLOT(OutLan()) );

    }
}

    void MainWindow::OutLan()
    {
        QProcess *p = dynamic_cast<QProcess *>( sender() );
        lancn=p->readLine();
    }
QString-lancn;
void main window::on_lineEditPathSet(QString inputpath)
{ 
QString parameters=“”+设置.value(“save_nmix”).toString()+“”+设置.value(“save_norm_method”).toString()+“”+设置.value(“save_oos_thresh”).toString()+“”+标志;
QString cmd=“test.exe”+输入路径+参数;
如果(p)
{
p->setEnvironment(QProcess::systemEnvironment());
p->setProcessChannelMode(QProcess::SeparateChannels);
p->启动(cmd);
p->waitForStarted();
连接(p,信号(readyReadStandardOutput()),此,插槽(OutTable());
连接(p,信号(readyReadStandardError()),此,插槽(ErrConsole());
}
QMessageBox msgBox(此);
msgBox.setWindowTitle(“启动测试过程”);
msgBox.setText(“正在初始化测试进程。\n\n这可能需要一些时间。\n\n请稍候”);
setIcon(QMessageBox::信息);
msgBox.exec();
if(lang_method.compare(“convalnet”)==0)
{
qprocesspr;
QStringList参数;
参数附加(“test.py”);
参数append(inputpath);
pr.start(“python”,参数);
waitForStarted()公关;
连接(&pr,信号(readyReadStandardOutput()),此,插槽(OutLan());
}
}
void主窗口::外域()
{
QProcess*p=动态_转换(发送方());
lancn=p->readLine();
}
输出:

QProcess:进程(“python”)仍在运行时被销毁


请告诉我进程(pr)被终止的原因?

您的
QProcess
是一个局部变量,当它超出范围时将被销毁。@G.M.谢谢。成功了。还有一个问题:当在包含多个文件的文件夹上调用程序test.py时,只调用一次extlan函数,即只调用第一个文件。你能告诉我原因吗?不能不看完整的代码(包括
test.py
)就说。然而,作为第一个猜测,我怀疑
test.py
正在缓冲输出,或者您的
OutLan
实现无法读取所有可用的输入。试着
while(p->canReadLine()){lancn=p->readLine();}
看看这是否有什么区别。@G.M.你是正确的。成功了。非常感谢你的帮助。