本文整理汇总了C++中QProcess::setStandardOutputProcess方法的典型用法代码示例。如果您正苦于以下问题:C++ QProcess::setStandardOutputProcess方法的具体用法?C++ QProcess::setStandardOutputProcess怎么用?C++ QProcess::setStandardOutputProcess使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QProcess
的用法示例。
在下文中一共展示了QProcess::setStandardOutputProcess方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
bool CameraOutV4L2::sudo(const QString &command,
const QStringList &argumments,
const QString &password) const
{
if (password.isEmpty())
return false;
QProcess echo;
QProcess su;
echo.setStandardOutputProcess(&su);
switch (this->m_rootMethod) {
case RootMethodSu: {
QStringList args;
for (QString arg: argumments)
args << arg.replace(" ", "\\ ");
echo.start("echo", {password});
su.start("su", {"-c", command + " " + args.join(" ")});
break;
}
case RootMethodSudo: {
echo.start("echo", {password});
su.start("sudo", QStringList{"-S", command} << argumments);
break;
}
}
su.setProcessChannelMode(QProcess::ForwardedChannels);
echo.waitForStarted();
if (!su.waitForFinished(this->m_passwordTimeout)) {
su.kill();
echo.waitForFinished();
return false;
}
echo.waitForFinished();
if (su.exitCode()) {
QByteArray outMsg = su.readAllStandardOutput();
if (!outMsg.isEmpty())
qDebug() << outMsg.toStdString().c_str();
QByteArray errorMsg = su.readAllStandardError();
if (!errorMsg.isEmpty())
qDebug() << errorMsg.toStdString().c_str();
return false;
}
return true;
}
示例2: start
void Action::start()
{
if ( m_cmds.isEmpty() )
return;
if ( m_cmds.size() > 1 ) {
QProcess *lastProcess = new QProcess(this);
m_firstProcess = lastProcess;
for ( int i = 0; i + 1 < m_cmds.size(); ++i ) {
const QStringList &args = m_cmds[i];
if (args.isEmpty())
continue;
QProcess *process = (i + 2 == m_cmds.size()) ? this : new QProcess(this);
lastProcess->setStandardOutputProcess(process);
lastProcess->start(args.first(), args.mid(1), QIODevice::ReadWrite);
lastProcess = process;
}
} else {
m_firstProcess = this;
}
const QStringList &args = m_cmds.last();
QProcess::start(args.isEmpty() ? QString() : args.first(), args.mid(1), QIODevice::ReadWrite);
}
示例3: executeJob
QByteArray executeJob(const Job& job)
{
QProcess sox;
QProcess lame;
// (1) SoX /////////////////////////////////////////////////////////////////
sox.setProgram(job.soxExe);
// Command Line: sox <input1> ... <inputN> -t wav -
#if defined(Q_OS_WIN)
QString sox_args;
foreach(const QString& input, job.inputFiles) {
sox_args += _L1C('"');
sox_args += input;
sox_args += _L1C('"');
sox_args += _L1C(' ');
}
sox_args += _L1("-t wav -"); // NOTE: Trailing <SPACE> Above!
sox.setNativeArguments(sox_args);
#else
QStringList sox_args;
sox_args << job.inputFiles << _L1("-t") << _L1("wav") << _L1("-");
sox.setArguments(sox_args);
#endif
// (2) LAME ////////////////////////////////////////////////////////////////
lame.setProgram(job.lameExe);
// Command Line: lame <options> -S - <output>
#if defined(Q_OS_WIN)
QString lame_args;
lame_args += job.lameOptions;
lame_args += _L1(" -S - ");
lame_args += _L1C('"');
lame_args += job.outputFile;
lame_args += _L1C('"');
lame.setNativeArguments(lame_args);
#else
QStringList lame_args;
lame_args << job.lameOptions << _L1("-S") << _L1("-") << job.outputFile;
lame.setArguments(lame_args);
#endif
// (3) Execute /////////////////////////////////////////////////////////////
sox.setStandardOutputProcess(&lame);
sox.start();
lame.start();
sox.waitForFinished(-1);
lame.waitForFinished(-1);
QByteArray result;
result += sox.readAllStandardError();
result += '\n';
result += lame.readAllStandardError();
if( job.renameInput ) {
foreach(const QString& input, job.inputFiles) {
QFile::rename(input, input+_L1(".done"));
}
}
示例4: setStandardOutputProcess
void QProcessProto::setStandardOutputProcess(QProcess *destination)
{
QProcess *item = qscriptvalue_cast<QProcess*>(thisObject());
if (item)
item->setStandardOutputProcess(destination);
}
示例5: HandleFile
void PackageProcessor::HandleFile (int packageId,
const QUrl& url, PackageProcessor::Mode mode)
{
QString path = Core::Instance ().GetExtResourceManager ()->GetResourcePath (url);
PackageShortInfo info;
try
{
info = Core::Instance ().GetStorage ()->GetPackage (packageId);
}
catch (const std::exception& e)
{
qWarning () << Q_FUNC_INFO
<< "unable to get package info for"
<< packageId
<< e.what ();
return;
}
const QString& archiver = info.VersionArchivers_
.value (info.Versions_.value (0), "gz");
QProcess *unarch = new QProcess (this);
connect (unarch,
SIGNAL (finished (int, QProcess::ExitStatus)),
this,
SLOT (handlePackageUnarchFinished (int, QProcess::ExitStatus)));
connect (unarch,
SIGNAL (error (QProcess::ProcessError)),
this,
SLOT (handleUnarchError (QProcess::ProcessError)));
QString dirname = Util::GetTemporaryName ("lackman_stagingarea");
QStringList args;
#ifdef Q_OS_WIN32
args << "x"
<< "-ttar"
<< "-y"
<< "-si";
QString outDirArg ("-o");
outDirArg.append (dirname);
args << outDirArg;
QProcess *firstStep = new QProcess (unarch);
firstStep->setStandardOutputProcess (unarch);
QStringList firstStepArgs;
firstStepArgs << "x"
<< "-y"
<< "-so"
<< path;
#else
if (archiver == "lzma")
args << "--lzma";
args << "-xf";
args << path;
args << "-C";
args << dirname;
#endif
unarch->setProperty ("PackageID", packageId);
unarch->setProperty ("StagingDirectory", dirname);
unarch->setProperty ("Path", path);
unarch->setProperty ("Mode", mode);
QFileInfo sdInfo (dirname);
QDir stagingParentDir (sdInfo.path ());
if (!stagingParentDir.exists (sdInfo.fileName ()) &&
!stagingParentDir.mkdir (sdInfo.fileName ()))
{
qWarning () << Q_FUNC_INFO
<< "unable to create staging directory"
<< sdInfo.fileName ()
<< "in"
<< sdInfo.path ();
QString errorString = tr ("Unable to create staging directory %1.")
.arg (sdInfo.fileName ());
emit packageInstallError (packageId, errorString);
return;
}
#ifdef Q_OS_WIN32
QString command = "7za";
firstStep->start (command, firstStepArgs);
#else
QString command = "tar";
#endif
unarch->start (command, args);
}