QProcess 启动win第三方程序

我不知道哪里错了

    prog = new QProcess(this);
    QString fullpath = QString("%1/%2").arg(QCoreApplication::applicationDirPath()).arg(exeName);
    qDebug() << "launch full path =" << fullpath << ", argv =" << argv;
    prog->setObjectName(fullpath);
    connect(prog, SIGNAL(finished(int,QProcess::ExitStatus)),
            this, SLOT(finishedSlot(int,QProcess::ExitStatus)));
    prog->start(fullpath, argv);
 如果这样写就启动不起来。 



下面写的就可以

    m_pOtherProcess = new QProcess(this);
    QString t_otherExePath = QString("%1/%2").arg(QCoreApplication::applicationDirPath()).arg(otherExeName);
    QString t_otherExeDirPath = QString("%1").arg(QCoreApplication::applicationDirPath());
    if(!QFile::exists(t_otherExePath))
    {
        qDebug()<<"robin:otherExe not exist";
        return -1;
    }
    connect(m_pOtherProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
            this, SLOT(finishedSlot(int,QProcess::ExitStatus)));
    m_pOtherProcess->setObjectName(t_otherExePath);
    m_pOtherProcess->setWorkingDirectory(t_otherExeDirPath);
    m_pOtherProcess->setProgram(t_otherExePath);
    m_pOtherProcess->start();


我不想找原因了,我要忙别的了。其实上面的代码之前也是可以的,但是不知道为什么不行了



下面是终极办法,肯定可以。

bool runWinExe(const QString &path)
{
	Q_ASSERT(QFile::exists(path));
	bool run = false;
#if defined(Q_OS_WIN)
	SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFO) };
	sei.lpVerb = TEXT("runas");
	WCHAR wfile[256];
	memset(wfile, 0, sizeof(wfile));
	path.toWCharArray(wfile);
	sei.lpFile = wfile;//add  application  which you want to run as administrator here
	sei.nShow = SW_SHOWNORMAL;//without this,the windows will be hiden
	run = ShellExecuteEx(&sei);
#else
	run = QProcess::startDetached(path);
#endif
	return run;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值