本文整理汇总了C++中QProcess::setEnvironment方法的典型用法代码示例。如果您正苦于以下问题:C++ QProcess::setEnvironment方法的具体用法?C++ QProcess::setEnvironment怎么用?C++ QProcess::setEnvironment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QProcess
的用法示例。
在下文中一共展示了QProcess::setEnvironment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QStringList
QHash<QString, QString>
KernelModel::getInstalledPackages() const
{
QProcess process;
process.setEnvironment( QStringList() << "LANG=C" << "LC_MESSAGES=C" );
process.start( "pacman", QStringList() << "-Qs" << "^linux[0-9][0-9]?([0-9])" );
if ( !process.waitForFinished( 15000 ) )
qDebug() << "error: failed to get all installed kernels";
QString result = process.readAll();
QHash<QString, QString> packages;
for ( QString line : result.split( "\n", QString::SkipEmptyParts ) )
{
if ( line.isEmpty() )
continue;
if ( line[0].isSpace() )
continue;
QStringList parts = line.split( ' ' );
QString repoName = parts.value( 0 );
int a = repoName.indexOf( "/" );
QString pkgName = repoName.mid( a+1 );
QString pkgVersion = parts.value( 1 );
packages.insert( pkgName, pkgVersion );
}
return packages;
}
示例2: programPath
QProcess * Engine::run(QFileInfo input, QObject * parent /* = nullptr */)
{
QString exeFilePath = programPath(program());
if (exeFilePath.isEmpty())
return nullptr;
QStringList env = QProcess::systemEnvironment();
QProcess * process = new QProcess(parent);
QString workingDir = input.canonicalPath();
#if defined(Q_OS_WIN)
// files in the root directory of the current drive have to be handled specially
// because QFileInfo::canonicalPath() returns a path without trailing slash
// (i.e., a bare drive letter)
if (workingDir.length() == 2 && workingDir.endsWith(QChar::fromLatin1(':')))
workingDir.append(QChar::fromLatin1('/'));
#endif
process->setWorkingDirectory(workingDir);
#if !defined(Q_OS_DARWIN) // not supported on OS X yet :(
// Add a (customized) TEXEDIT environment variable
env << QString::fromLatin1("TEXEDIT=%1 --position=%d %s").arg(QCoreApplication::applicationFilePath());
#if defined(Q_OS_WIN) // MiKTeX apparently uses it's own variable
env << QString::fromLatin1("MIKTEX_EDITOR=%1 --position=%l \"%f\"").arg(QCoreApplication::applicationFilePath());
#endif
#endif
QStringList args = arguments();
#if !defined(MIKTEX)
// for old MikTeX versions: delete $synctexoption if it causes an error
static bool checkedForSynctex = false;
static bool synctexSupported = true;
if (!checkedForSynctex) {
QString pdftex = programPath(QString::fromLatin1("pdftex"));
if (!pdftex.isEmpty()) {
int result = QProcess::execute(pdftex, QStringList() << QString::fromLatin1("-synctex=1") << QString::fromLatin1("-version"));
synctexSupported = (result == 0);
}
checkedForSynctex = true;
}
if (!synctexSupported)
args.removeAll(QString::fromLatin1("$synctexoption"));
#endif
args.replaceInStrings(QString::fromLatin1("$synctexoption"), QString::fromLatin1("-synctex=1"));
args.replaceInStrings(QString::fromLatin1("$fullname"), input.fileName());
args.replaceInStrings(QString::fromLatin1("$basename"), input.completeBaseName());
args.replaceInStrings(QString::fromLatin1("$suffix"), input.suffix());
args.replaceInStrings(QString::fromLatin1("$directory"), input.absoluteDir().absolutePath());
process->setEnvironment(env);
process->setProcessChannelMode(QProcess::MergedChannels);
process->start(exeFilePath, args);
return process;
}
示例3: runCommand
bool TestCompiler::runCommand( QString cmdline )
{
testOutput_.append("Running command: " + cmdline);
QProcess child;
if (!environment_.empty())
child.setEnvironment(QProcess::systemEnvironment() + environment_);
child.start(cmdline);
if (!child.waitForStarted(-1)) {
testOutput_.append( "Unable to start child process." );
return false;
}
bool failed = false;
child.setReadChannel(QProcess::StandardError);
child.waitForFinished(-1);
foreach (const QByteArray &output, child.readAllStandardError().split('\n')) {
testOutput_.append(QString::fromLocal8Bit(output));
if (output.startsWith("Project MESSAGE: FAILED"))
failed = true;
}
return !failed && child.exitStatus() == QProcess::NormalExit && child.exitCode() == 0;
}
示例4: alsaDevices
DeviceList DeviceInfo::alsaDevices()
{
qDebug("DeviceInfo::alsaDevices");
DeviceList l;
QRegExp rx_device("^card\\s([0-9]+).*\\[(.*)\\],\\sdevice\\s([0-9]+):");
QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);
p.setEnvironment(QStringList() << "LC_ALL=C");
p.start("aplay", QStringList() << "-l");
if (p.waitForFinished()) {
QByteArray line;
while (p.canReadLine()) {
line = p.readLine();
qDebug("DeviceInfo::alsaDevices: '%s'", line.constData());
if (rx_device.indexIn(line) > -1) {
QString id = rx_device.cap(1);
id.append(".");
id.append(rx_device.cap(3));
QString desc = rx_device.cap(2);
qDebug("DeviceInfo::alsaDevices: found device: '%s' '%s'", id.toUtf8().constData(), desc.toUtf8().constData());
l.append(DeviceData(id, desc));
}
}
} else {
qDebug("DeviceInfo::alsaDevices: could not start aplay, error %d", p.error());
}
return l;
}
示例5: xvAdaptors
DeviceList DeviceInfo::xvAdaptors()
{
qDebug("DeviceInfo::xvAdaptors");
DeviceList l;
QRegExp rx_device("^.*Adaptor #([0-9]+): \"(.*)\"");
QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);
p.setEnvironment(QProcess::systemEnvironment() << "LC_ALL=C");
p.start("xvinfo");
if (p.waitForFinished()) {
QByteArray line;
while (p.canReadLine()) {
line = p.readLine();
qDebug("DeviceInfo::xvAdaptors: '%s'", line.constData());
if (rx_device.indexIn(line) > -1) {
QString id = rx_device.cap(1);
QString desc = rx_device.cap(2);
qDebug("DeviceInfo::xvAdaptors: found adaptor: '%s' '%s'", id.toUtf8().constData(), desc.toUtf8().constData());
l.append(DeviceData(id, desc));
}
}
} else {
qDebug("DeviceInfo::xvAdaptors: could not start xvinfo, error %d", p.error());
}
return l;
}
示例6: QgsDebugMsg
QProcess *QgsContextHelp::start()
{
// Get the path to the help viewer
QString helpPath = QgsApplication::helpAppPath();
QgsDebugMsg( QString( "Help path is %1" ).arg( helpPath ) );
QProcess *process = new QProcess;
// Delete this object if the process terminates
connect( process, SIGNAL( finished( int, QProcess::ExitStatus ) ), SLOT( processExited() ) );
// Delete the process if the application quits
connect( qApp, SIGNAL( aboutToQuit() ), process, SLOT( terminate() ) );
connect( process, SIGNAL( error( QProcess::ProcessError ) ), this, SLOT( error( QProcess::ProcessError ) ) );
#ifdef Q_OS_WIN
if ( QgsApplication::isRunningFromBuildDir() )
{
process->setEnvironment( QStringList() << QString( "PATH=%1;%2" ).arg( getenv( "PATH" ) ).arg( QApplication::applicationDirPath() ) );
}
#endif
process->start( helpPath, QStringList() );
return process;
}
示例7: alsaDevices
TDeviceList TDeviceInfo::alsaDevices() {
Log4Qt::Logger* logger = Log4Qt::Logger::logger("Gui::TDeviceInfo");
logger->debug("alsaDevices");
TDeviceList l;
QRegExp rx_device("^card\\s([0-9]+).*\\[(.*)\\],\\sdevice\\s([0-9]+):");
QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);
p.setEnvironment(QStringList() << "LC_ALL=C");
p.start("aplay", QStringList() << "-l");
if (p.waitForFinished()) {
QByteArray line;
while (p.canReadLine()) {
line = p.readLine().trimmed();
if (rx_device.indexIn(line) >= 0) {
QString id = rx_device.cap(1);
id.append(".");
id.append(rx_device.cap(3));
QString desc = rx_device.cap(2);
logger->debug("alsaDevices: found device: '%1' '%2'", id, desc);
l.append(TDeviceData(id, desc));
}
}
} else {
logger->warn("alsaDevices: could not start aplay, error %1", p.error());
}
return l;
}
示例8: getGSLinuxPath
QString getGSLinuxPath( QString apps )
{
QStringList potential_paths;
potential_paths.append("/usr/local/bin");
potential_paths.append("/sw/bin"); /* to use on mac as same */
potential_paths.append("/opt/bin");
QProcess *process = new QProcess(NULL);
process->setReadChannelMode(QProcess::MergedChannels);
QStringList env = process->systemEnvironment();
env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=\\1;"+potential_paths.join(";"));
process->setEnvironment(env);
process->start( QString("which") , QStringList() << apps , QIODevice::ReadOnly );
if (!process->waitForFinished()) {
return QString();
} else {
QString finder = process->readAll().trimmed();
if (finder.endsWith(apps,Qt::CaseInsensitive)) {
///////////// qDebug() << "### finder " << finder;
return finder;
} else {
return QString();
}
}
}
示例9: mount
bool MountManager::mount()
{
if(!isPasswordCorrect()){
return false;
}
if(mountedDirExists()){
emit errorString(QString(QLatin1String("Already have something mounted in %1 ...continue")).arg(m_mountdir));
return true;
}
if(!QFileInfo(m_imgdir).exists()){
emit errorString(m_imgdir+QLatin1String("file does not exists\n"));
return false;
}
QProcess proc;
proc.setEnvironment(QProcess::systemEnvironment());
proc.start(QString(QLatin1String("sh -c \"echo %1 | sudo -S mount -o loop %2 %3\"")).arg(m_userPassWord).arg(m_imgdir).arg(m_mountdir));
if(!proc.waitForFinished()){
emit errorString(QString(QLatin1String("Can't mount image %1")).arg(QString(proc.errorString())));
return false;
}
if(!mountedDirExists()){
proc.waitForReadyRead();
emit errorString(QLatin1String(proc.readAllStandardError()));
return false;
}
proc.terminate();
messageString(QString(QLatin1String("Image mounted in %1")).arg(m_mountdir));
return true;
}
示例10: runWithQtInEnvironment
static bool runWithQtInEnvironment(const QString &cmd)
{
QProcess proc;
// prepend the qt binary directory to the path
QStringList env = QProcess::systemEnvironment();
for (int i=0; i<env.count(); ++i) {
QString var = env.at(i);
int setidx = var.indexOf(QLatin1Char('='));
if (setidx != -1) {
QString varname = var.left(setidx).trimmed().toUpper();
if (varname == QLatin1String("PATH")) {
var = var.mid(setidx + 1);
var = QLatin1String("PATH=") +
QLibraryInfo::location(QLibraryInfo::BinariesPath) +
QLatin1Char(';') + var;
env[i] = var;
break;
}
}
}
proc.setEnvironment(env);
proc.start(cmd);
proc.waitForFinished(-1);
return (proc.exitCode() == 0);
}
示例11: xvAdaptors
TDeviceList TDeviceInfo::xvAdaptors() {
Log4Qt::Logger* logger = Log4Qt::Logger::logger("Gui::TDeviceInfo");
logger->debug("xvAdaptors");
TDeviceList l;
QRegExp rx_device("^Adaptor #([0-9]+): \"(.*)\"");
QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);
p.setEnvironment(QProcess::systemEnvironment() << "LC_ALL=C");
p.start("xvinfo");
if (p.waitForFinished()) {
while (p.canReadLine()) {
QString s = QString::fromLocal8Bit(p.readLine()).trimmed();
logger->trace("xvAdaptors: line '%1'", s);
if (rx_device.indexIn(s) >= 0) {
QString id = rx_device.cap(1);
QString desc = rx_device.cap(2);
logger->debug("xvAdaptors: found adaptor: '" + id
+ " '" + desc + "'");
l.append(TDeviceData(id, desc));
}
}
} else {
logger->warn("xvAdaptors: could not start xvinfo, error %1", p.error());
}
return l;
}
示例12: runCommand
bool TestCompiler::runCommand( QString cmdline )
{
testOutput_.append("Running command: " + cmdline);
QProcess child;
if (!environment_.empty())
child.setEnvironment(QProcess::systemEnvironment() + environment_);
child.start(cmdline);
if (!child.waitForStarted(-1)) {
testOutput_.append( "Unable to start child process." );
return false;
}
bool failed = false;
child.setReadChannel(QProcess::StandardError);
while (QProcess::Running == child.state()) {
if (child.waitForReadyRead(1000)) {
QString output = child.readAllStandardError();
testOutput_.append(output);
output.prepend('\n');
if (output.contains("\nProject MESSAGE: FAILED"))
failed = true;
}
}
child.waitForFinished(-1);
return failed
? false
: (child.exitStatus() == QProcess::NormalExit)
&& (child.exitCode() == 0);
}
示例13: runUic
bool UiCodeModelSupport::runUic(const QString &ui) const
{
QProcess process;
const QString uic = uicCommand();
process.setEnvironment(environment());
if (debug)
qDebug() << "UiCodeModelSupport::runUic " << uic << " on " << ui.size() << " bytes";
process.start(uic, QStringList(), QIODevice::ReadWrite);
if (!process.waitForStarted())
return false;
process.write(ui.toUtf8());
process.closeWriteChannel();
if (process.waitForFinished() && process.exitStatus() == QProcess::NormalExit && process.exitCode() == 0) {
m_contents = process.readAllStandardOutput();
m_cacheTime = QDateTime::currentDateTime();
if (debug)
qDebug() << "ok" << m_contents.size() << "bytes.";
return true;
} else {
if (debug)
qDebug() << "failed" << process.readAllStandardError();
process.kill();
}
return false;
}
示例14: stepOut
void DlvDebugger::stepOut()
{
QString cmd = LiteApi::getGotools(m_liteApp);
QProcess process;
process.setEnvironment(LiteApi::getCurrentEnvironment(m_liteApp).toStringList());
QFileInfo info(m_lastFileName);
process.setWorkingDirectory(info.path());
QStringList args;
args << "finddecl" << "-file" << info.fileName() << "-line" << QString("%1").arg(m_lastFileLine+1);
process.start(cmd,args);
if (!process.waitForFinished(3000)) {
emit debugLog(LiteApi::DebugErrorLog,"error wait find decl process");
process.kill();
return;
}
if (process.exitCode() != 0) {
emit debugLog(LiteApi::DebugErrorLog,"error get find decl result");
return;
}
QByteArray data = process.readAll().trimmed();
QStringList ar = QString::fromUtf8(data).split(" ");
if (ar.size() != 4 || ar[0] != "func") {
emit debugLog(LiteApi::DebugErrorLog,"error find func decl in line");
return;
}
m_funcDecl.fileName = m_lastFileName;
m_funcDecl.funcName = ar[1];
m_funcDecl.start = ar[2].toInt()-1;
m_funcDecl.end = ar[3].toInt()-1;
m_checkFuncDecl = true;
command("next");
}
示例15: run
void ImportThread::run()
{
QProcess compileProcess;
QString processBin = QString();
if ((Preferences::p_getCompiler()=="latex")||(Preferences::p_getCompiler()=="tex"))
{
processBin=Preferences::p_getLtx2pdf();
}
else processBin=Preferences::p_getBin(Preferences::p_getCompiler());
#ifndef Q_OS_WIN
QStringList env = QProcess::systemEnvironment();
int j = env.indexOf(QRegExp("^PATH=(.*)"));
int limit = env.at(j).indexOf("=");
QString value = env.at(j).right(env.at(j).size()-limit-1).trimmed();
value = "PATH=" + value + ":" + QFileInfo(processBin).path() + ":" + QFileInfo(Preferences::p_getBin("latex")).path() + ":" + QFileInfo(Preferences::p_getBin("dvips")).path() + ":" + QFileInfo(Preferences::p_getBin("ps2pdf")).path();
env.replace(j,value);
compileProcess.setEnvironment(env);
#endif
int listLen = fileList.size();
QString exoFile;
QMap<QString,QString> * exoMap = new QMap<QString,QString>;
for (int i=0; i<listLen; i++)
{
exoMap = new QMap<QString,QString>;
*exoMap = fileList.at(i);
exoFile = exoMap->value("filepath");
compileProcess.setWorkingDirectory(QFileInfo(exoFile).path());
QStringList args;
QString tmpFileName = QFileInfo(exoFile).baseName() + "-preview.tex";
if ((Preferences::p_getCompiler()=="latex")||(Preferences::p_getCompiler()=="tex"))
{
#ifdef Q_OS_WIN
args << QFileInfo(exoFile).baseName() + "-preview" << Preferences::p_getBin("latex") << Preferences::p_getBin("dvips") << Preferences::p_getBin("ps2pdf") << Preferences::p_getCompilationOptions();
#else
args << "-c" << tmpFileName << Preferences::p_getBin("latex") << Preferences::p_getBin("dvips") << Preferences::p_getBin("ps2pdf") << Preferences::p_getCompilationOptions();
// args << "-c" << tmpFileName << "latex" << "dvips" << "ps2pdf" << Preferences::p_getCompilationOptions();
#endif
}
else args << Preferences::p_getCompilationOptions() << tmpFileName;
// On exécute la compilation
compileProcess.start(processBin,args);
compileProcess.waitForFinished(-1);
QString errorOutput = compileProcess.readAll();
QString outName=QString();
outName = QFileInfo(exoFile).path() + QDir::separator()+ QFileInfo(exoFile).baseName()+"-preview.pdf";
QFile outFile;
if (outFile.exists(outName)) { emit exoTreated(exoMap); }
else emit errorOccured(exoFile,errorOutput);
exoMap->~QMap();
}
}