问题描述
- Qt关闭QProcess打开的进程问题
-
槽函数如下,用QProcess打开Windows计算器,但是问什么关不了这个进程?求大神指导
void MainWindow::on_buttonBox_clicked(QAbstractButton *button)
{
if(ui->buttonBox->button(QDialogButtonBox::Ok) == button)
{
QString str = "C:/WINDOWS/System32/calc.exe";
process = new QProcess(this);
QString string;
//process->setProcessChannelMode(QProcess::MergedChannels);
qDebug()<isOpen();
process->start(str.trimmed());//trimmed()函数去除字符串最后空格
str1 = process->processId();
ui->lineEdit->setText(QString::number(str1));
qDebug()<
bool bo = process->isOpen();
qDebug()<
string = process->Text;
qDebug()<
p = process->pid();
}
else if(ui->buttonBox->button(QDialogButtonBox::Cancel) == button)
{
qDebug()<
qDebug()isOpen();
if(process->isOpen())
{
HANDLE hApp = OpenProcess(PROCESS_QUERY_INFORMATION
| PROCESS_TERMINATE, FALSE, str1);
if (hApp == NULL) return;
TerminateProcess(hApp, NULL);
CloseHandle(hApp);
}
}
}
解决方案
参考:http://blog.chinaunix.net/uid-26808060-id-3347391.html
时间: 2024-12-31 21:05:22