Qt获取当前程序运行路径
#include <QCoreApplication>
QString applicationDirPath = QCoreApplication::applicationDirPath();
选择文件夹路径
QString file_path = QFileDialog::getExistingDirectory(this, "请选择文件夹路径...", "./");
qDebug()<<"file_path:"<<file_path;
if(file_path.isEmpty())
{ return; }
运行外部程序
void Widget::on_pBtn_Start_clicked()
{
QString cmd = applicationDirPath + "/Alg.exe";
if(file_path.isEmpty())
return ;
QString argument = file_path + " " + "100 200 101.3 25 s2019";
QStringList args = argument.split(" ");
QProcess program;
program.start(cmd, args);
program.waitForFinished();
}
qDebug()调试输出
file_path: "C:/Users/Administrator/Desktop/Files1"
applicationDirPath: "C:/Users/Administrator/Documents/qt_dir/build-alg-Desktop_Qt_5_14_2_MinGW_64_bit-Debug/debug"