QProcess应用

利用QProcess调用外部程序,并传递参数

//typedef QProcess::CreateProcessArgumentModifier
//Note: This typedef is only available on desktop Windows.
include <Windows.h>
QString program = "C:/Windows/System32/notepad.exe"; 
QProcess *myProcess = new QProcess();
myProcess->setCreateProcessArgumentsModifier([]QProcess::CreateProcessArguments *args)
{
  args->startupInfo->wShowWindow = SW_HIDE;
  args->startupInfo->dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
});//显示外部程序的界面
myProcess ->start(program, QStringList()<<"Hello World"); //调用第三方程序,其中QStringList中含传入的参数

Qt程序接受输入参数

int main(int argc, char* argv[]) 
{
    QApplication a(argc, argv);
    qDebuf()<<argc; //argc输入参数个数
    for(int i = 0;i<argc;i++)
    {
        qDebuf()<<argv[i]; //输出具体参数 
    }
    MainWindow w;
    w.show();
    return a.exec();
}

你可能感兴趣的:(Qt)