QT:打开外部程序

论坛 期权论坛 脚本     
匿名网站用户   2020-12-20 23:39   81   0

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参数补充上。
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP