RasterProcessTool/Toolbox/KJ135WBJYAlgInterfaceToolbox/QWBFZExcuteAlgProgramDialog...

95 lines
3.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "QWBFZExcuteAlgProgramDialog.h"
#include "ui_QWBFZExcuteAlgProgramDialog.h"
#include "KJ135WBJYAlgWidgetComponet.h"
#include <QProcess>
#include <qt_windows.h>
QWBFZExcuteAlgProgramDialog::QWBFZExcuteAlgProgramDialog(QWidget *parent)
: QDialog(parent),
ui(new Ui::QWBFZExcuteAlgProgramDialogClass),
xmlfileSelectWidget(new FileSelectWidget(this)),
exefileSelectWidget(new FileSelectWidget(this))
{
ui->setupUi(this);
// 添加参数选择组件
exefileSelectWidget->setParaName(u8"算法执行exe");
exefileSelectWidget->setParaChsName(u8"算法执行exe");
exefileSelectWidget->setDescription(u8"算法执行exe");
exefileSelectWidget->setDatatype(u8"string");
exefileSelectWidget->setParaType(u8"Value");
exefileSelectWidget->setComponentType(ComponentType::FileSelect);
exefileSelectWidget->initUI();
xmlfileSelectWidget->setParaName(u8"算法xml参数文件");
xmlfileSelectWidget->setParaChsName(u8"算法xml参数文件");
xmlfileSelectWidget->setDescription(u8"算法xml参数文件");
xmlfileSelectWidget->setDatatype(u8"string");
xmlfileSelectWidget->setParaType(u8"Value");
xmlfileSelectWidget->setComponentType(ComponentType::FileSelect);
xmlfileSelectWidget->initUI();
ui->verticalLayout_InParamsRegion->addWidget(exefileSelectWidget);
ui->verticalLayout_InParamsRegion->addWidget(xmlfileSelectWidget);
// 连接信号槽
QObject::connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onacceptButton_Clicked()));
QObject::connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(oncancelButton_Clicked()));
this->show();
}
QWBFZExcuteAlgProgramDialog::~QWBFZExcuteAlgProgramDialog()
{
delete ui;
}
void QWBFZExcuteAlgProgramDialog::onacceptButton_Clicked()
{
QString xmlfilepath = xmlfileSelectWidget->getValue();
QString exefilepath = exefileSelectWidget->getValue();
qDebug() <<"xmlpath :\t" << xmlfilepath;
qDebug() << "exepath :\t" << exefilepath;
// 获取exe文件文件夹路径
QString exeDirPath = QFileInfo(exefilepath).absolutePath();
qDebug() << "exedirpath :\t" << exeDirPath;
// 构建cmd命令先进入exe文件所在目录然后执行exe文件参数为xml文件路径
QString cmdstr = QString("cd /d %1 && %2 %3").arg(exeDirPath).arg(exefilepath).arg(xmlfilepath);
qDebug() << "cmdstr :\t" << cmdstr;
// 执行cmd命令
QProcess* process = new QProcess(this);
process->setProcessChannelMode(QProcess::MergedChannels);
// 设置Windows API参数强制弹出窗口
process->setCreateProcessArgumentsModifier([](QProcess::CreateProcessArguments* args) {
args->flags |= CREATE_NEW_CONSOLE; // 创建新控制台窗口
args->startupInfo->wShowWindow = SW_SHOWNORMAL; // 正常显示窗口
args->startupInfo->dwFlags &= ~STARTF_USESTDHANDLES; // 禁用标准句柄重定向[3,7](@ref)
});
// 实时读取命令输出
connect(process, &QProcess::readyRead, [=]() {
QString output = QString::fromLocal8Bit(process->readAll());
qDebug() << "CMD Output:" << output;
});
// 设置程序路径和参数
process->start("cmd.exe", QStringList() << "/k" << cmdstr);
// 错误处理
connect(process, &QProcess::errorOccurred, [](QProcess::ProcessError error) {
qDebug() << "Error:" << error;
});
}
void QWBFZExcuteAlgProgramDialog::oncancelButton_Clicked()
{
this->close();
}