QT:打开外部程序

    xiaoxiao2026-03-30  10

    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参数补充上。
    转载请注明原文地址: https://ju.6miu.com/read-1308318.html
    最新回复(0)