QT:打開外部程序

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;//參數list
    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參數補充上。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章