1. 使用QProcess的startDetached函數。
startDetached函數有三種原型:
static bool startDetached(const QString &program, const QStringList &arguments,
const QString &workingDirectory
static bool startDetached(const QString &program, const QStringList &arguments);
static bool startDetached(const QString &command);
#include <QProcess>
QStringList strList;
strList << "1" << "2";
QProcess::startDetached("D://02_wind//main//Wind.exe", strList, "D://02_wind//main");
注意:在使用過程中,所打開的exe文件不加載配置文件,則需要指定工作路徑,即將workingDirectory參數補充上。
2.使用WINAPI的shellExecute函數。
函數原型:
HINSTANCE ShellExecute(
HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);
#include <shellapi.h>
#include <ShlObj.h>
#include <qt_windows.h>
ShellExecute(NULL, L"open", L"D://02_wind//main//Wind.exe", NULL, L"D://02_wind//main", SW_SHOW);
注意:在使用過程中,所打開的exe文件不加載配置文件,則需要指定工作路徑,即將lpDirectory參數補充上。