本文整理汇总了C++中QProcessEnvironment类的典型用法代码示例。如果您正苦于以下问题:C++ QProcessEnvironment类的具体用法?C++ QProcessEnvironment怎么用?C++ QProcessEnvironment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QProcessEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QString
/**
* @brief KernelModel::getRunningKernel get running kernel in the system
* @return string with the version of running kernel
*/
QString
KernelModel::getRunningKernel() const
{
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert( "LANG", "C" );
env.insert( "LC_MESSAGES", "C" );
env.insert( "LC_ALL", "C" );
QProcess uname;
uname.setProcessEnvironment( env );
uname.start( "uname", QStringList() << "-r" );
uname.waitForFinished();
QString result = uname.readAllStandardOutput();
uname.close();
QStringList aux = result.split( ".", QString::SkipEmptyParts );
return QString( "linux%1%2" ).arg( aux.at( 0 ) ).arg( aux.at( 1 ) );
}
示例2: result
/*
* Performs a pacman query
*/
QByteArray UnixCommand::performQuery(const QStringList args)
{
QByteArray result("");
QProcess pacman;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("LANG", "C");
env.insert("LC_MESSAGES", "C");
env.insert("LC_ALL", "C");
pacman.setProcessEnvironment(env);
pacman.start("pacman", args);
pacman.waitForFinished();
result = pacman.readAllStandardOutput();
pacman.close();
return result;
}
示例3: runCommand
/*
* Executes given command and returns the StandardError Output.
*/
QString UnixCommand::runCommand(const QString& commandToRun)
{
QProcess proc;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.remove("LANG");
env.remove("LC_MESSAGES");
env.insert("LANG", "C");
env.insert("LC_MESSAGES", "C");
proc.setProcessEnvironment(env);
proc.start(commandToRun);
proc.waitForStarted();
proc.waitForFinished(-1);
QString res = proc.readAllStandardError();
proc.close();
return res;
}
示例4: m_app
App::App(QCoreApplication *application, const QString &sessionName)
: m_app(application)
, m_exitCode(0)
, m_closed(false)
{
QString session("copyq");
if ( !sessionName.isEmpty() ) {
session += "-" + sessionName;
m_app->setProperty( "CopyQ_session_name", QVariant(sessionName) );
}
#ifdef HAS_TESTS
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
if ( env.value("COPYQ_TESTING") == "1" )
session += ".test";
#endif
QCoreApplication::setOrganizationName(session);
QCoreApplication::setApplicationName(session);
const QString locale = QLocale::system().name();
QTranslator *translator = new QTranslator(m_app.data());
translator->load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
QCoreApplication::installTranslator(translator);
translator = new QTranslator(m_app.data());
translator->load("copyq_" + locale, ":/translations");
QCoreApplication::installTranslator(translator);
#ifdef Q_OS_UNIX
// Safely quit application on TERM and HUP signals.
struct sigaction sigact;
sigact.sa_handler = ::exitSignalHandler;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigact.sa_flags |= SA_RESTART;
if ( sigaction(SIGHUP, &sigact, 0) > 0
|| sigaction(SIGINT, &sigact, 0) > 0
|| sigaction(SIGTERM, &sigact, 0) > 0 )
log( QString("sigaction() failed!"), LogError );
#endif
}
示例5: writeSettings
void MainWindow::on_buttonBox_accepted() {
writeSettings();
QSettings settings(QSettings::IniFormat, QSettings::UserScope,
Organization, ProjectName);
QString ocrCmd;
if (settings.contains("OCR/program"))
ocrCmd = settings.value("OCR/program").toString();
// TODO(zdenop): check for missing setting or empty string
QStringList args;
QString in = ui->lineEditIn->text();
args << in;
QString out = ui->lineEditOut->text();
out = out.replace(".txt", "").replace(".html", "");
args << out;
QString lang = ui->comboBoxLang->itemData(
ui->comboBoxLang->currentIndex()).toString();
args << "-l" << lang;
if (ui->comboBoxPSM->isEnabled()) {
int PSM = ui->comboBoxPSM->currentIndex();
args << "-psm" << QString::number(PSM);
}
if (ui->comboBoxForm->currentIndex() == 1) {
args << "hocr";
}
if (!settings.value("OCR/sys_prefix").toBool()) {
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("TESSDATA_PREFIX", settings.value("OCR/prefix").toString());
process.setProcessEnvironment(env);
}
ui->tb_Log->appendHtml(tr("OCR program started..."));
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
process.start(ocrCmd, args);
}
示例6: main
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
// Try to get all of the env variables here
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
QStringList keys = environment.keys();
QList<QObject*> dataList;
foreach (QString key, keys) {
qDebug() << "key: " << key;
QString value = environment.value(key);
qDebug() << "value: " << value;
dataList.append(new DataObject(key, value));
}
示例7: qDebug
void QvkPulse::pulseUnloadModule()
{
//qDebug( " " );
qDebug() << "[vokoscreen] ---Begin Pulse unload Module---";
QProcess Process;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("LANG", "c");
Process.setProcessEnvironment(env);
Process.start( "pactl list" );
Process.waitForFinished();
QString output = Process.readAllStandardOutput();
Process.close();
QStringList list = output.split( "\n" );
QStringList modulNumberList;
QString str;
QString strLog;
for ( int i = 0; i < list.count(); i++ )
{
str = list[ i ];
if ( str.contains("vokoscreenMix", Qt::CaseInsensitive) )
{
str = list[ i - 2 ];
if ( str.contains("Module", Qt::CaseInsensitive) )
{
str.replace("Module #", "");
str.replace("\n", "");
modulNumberList.insert ( 0, str );
}
}
}
for ( int i = 0; i < modulNumberList.count(); i++ )
{
Process.start("pactl unload-module " + modulNumberList[ i ] );
Process.waitForFinished();
Process.close();
qDebug() << "[vokoscreen] pactl unload-module number" << modulNumberList[ i ] ;
}
qDebug() << "[vokoscreen] ---End Pulse unload Module---";
qDebug( " " );
}
示例8: launchProcess
bool ProcessInjector::launchProcess(const QStringList& programAndArgs, const QProcessEnvironment& env)
{
InteractiveProcess proc;
proc.setProcessEnvironment(env);
proc.setProcessChannelMode(QProcess::ForwardedChannels);
QStringList args = programAndArgs;
if (!env.value("GAMMARAY_TARGET_WRAPPER").isEmpty()) {
const QString fullWrapperCmd = env.value("GAMMARAY_TARGET_WRAPPER");
// ### TODO properly handle quoted arguments!
QStringList newArgs = fullWrapperCmd.split(' ');
newArgs += args;
args = newArgs;
qDebug() << "Launching with target wrapper:" << args;
} else if (env.value("GAMMARAY_GDB").toInt()) {
QStringList newArgs;
newArgs << "gdb";
#ifndef Q_OS_MAC
newArgs << "--eval-command" << "run";
#endif
newArgs << "--args";
newArgs += args;
args = newArgs;
}
const QString program = args.takeFirst();
proc.start(program, args);
proc.waitForFinished(-1);
mExitCode = proc.exitCode();
mProcessError = proc.error();
mExitStatus = proc.exitStatus();
mErrorString = proc.errorString();
if (mProcessError == QProcess::FailedToStart) {
mErrorString.prepend(QString("Could not start '%1': ").arg(program));
}
return mExitCode == EXIT_SUCCESS && mExitStatus == QProcess::NormalExit
&& mProcessError == QProcess::UnknownError;
}
示例9: compositorEnv
QProcessEnvironment CompositorLauncher::compositorEnv() const
{
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
// Standard environment
// env.insert(QStringLiteral("QT_QPA_PLATFORMTHEME"), QStringLiteral("Material"));
// env.insert(QStringLiteral("QT_QUICK_CONTROLS_STYLE"), QStringLiteral("Material"));
// env.insert(QStringLiteral("XCURSOR_THEME"), QStringLiteral("Adwaita"));
// env.insert(QStringLiteral("XCURSOR_SIZE"), QStringLiteral("16"));
env.insert(QStringLiteral("QSG_RENDER_LOOP"), QStringLiteral("windows"));
// Specific environment
switch (m_mode) {
case EglFSMode:
// General purpose distributions do not have the proper eglfs
// integration and may want to build it out of tree, let them
// specify a QPA plugin with an environment variable
if (qEnvironmentVariableIsSet("U2T_QPA_PLATFORM"))
env.insert(QStringLiteral("QT_QPA_PLATFORM"), qgetenv("U2T_QPA_PLATFORM"));
else
// FIXME this should not be eglfs and shold be xcb unless wayland
env.insert(QStringLiteral("QT_QPA_PLATFORM"), QStringLiteral("eglfs"));
switch (m_hardware) {
case BroadcomHardware:
env.insert(QStringLiteral("QT_QPA_EGLFS_INTEGRATION"), QStringLiteral("eglfs_brcm"));
break;
default:
env.insert(QStringLiteral("QT_QPA_EGLFS_INTEGRATION"), QStringLiteral("eglfs_kms"));
env.insert(QStringLiteral("QT_QPA_EGLFS_KMS_CONFIG"),
QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QStringLiteral("u2t-shell/eglfs/eglfs_kms.json")));
break;
}
if (m_hasLibInputPlugin)
env.insert(QStringLiteral("QT_QPA_EGLFS_DISABLE_INPUT"), QStringLiteral("1"));
break;
case X11Mode:
env.insert(QStringLiteral("QT_XCB_GL_INTEGRATION"), QStringLiteral("xcb_egl"));
break;
default:
break;
}
return env;
}
示例10: replaceWindowsEnvironmentVariables
QString QInstaller::replaceWindowsEnvironmentVariables(const QString &str)
{
const QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QString res;
int pos = 0;
while (true) {
int pos1 = str.indexOf(QLatin1Char( '%'), pos);
if (pos1 == -1)
break;
int pos2 = str.indexOf(QLatin1Char( '%'), pos1 + 1);
if (pos2 == -1)
break;
res += str.mid(pos, pos1 - pos);
QString name = str.mid(pos1 + 1, pos2 - pos1 - 1);
res += env.value(name);
pos = pos2 + 1;
}
res += str.mid(pos);
return res;
}
示例11: vcsCommandString
bool MercurialClient::synchronousPull(const QString &workingDir, const QString &srcLocation, const QStringList &extraOptions)
{
QStringList args;
args << vcsCommandString(PullCommand) << extraOptions << srcLocation;
// Disable UNIX terminals to suppress SSH prompting
const unsigned flags =
VcsCommand::SshPasswordPrompt
| VcsCommand::ShowStdOut
| VcsCommand::ShowSuccessMessage;
// cause mercurial doesn`t understand LANG
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert(QLatin1String("LANGUAGE"), QLatin1String("C"));
const SynchronousProcessResponse resp = VcsBasePlugin::runVcs(
workingDir, vcsBinary(), args, vcsTimeoutS(), flags, nullptr, env);
const bool ok = resp.result == SynchronousProcessResponse::Finished;
parsePullOutput(resp.stdOut().trimmed());
return ok;
}
示例12: doInternetPingTest
/*
* Pings google site, to make sure internet is OK
*/
bool UnixCommand::doInternetPingTest()
{
QProcess ping;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("LANG", "C");
env.insert("LC_MESSAGES", "C");
ping.setProcessEnvironment(env);
if (UnixCommand::getLinuxDistro() == ectn_MOOOSLINUX)
ping.start("torsocks ping -c 1 -W 3 www.google.com");
else
ping.start("ping -c 1 -W 3 www.google.com");
ping.waitForFinished();
int res = ping.exitCode();
ping.close();
return (res == 0);
}
示例13: QProcessEnvironmenttoScriptValue
// TODO: remove as much of this file as possible, as most of it isn't necessary
QScriptValue QProcessEnvironmenttoScriptValue(QScriptEngine *engine, const QProcessEnvironment &item)
{
QScriptValue result = engine->newObject();
QStringList env = item.toStringList();
for (int i = 0; i < env.size(); i++)
{
QStringList line = env[i].split("=");
result.setProperty(line[0], line[1]);
}
return result;
}
示例14: run
void GoplayBrowser::run()
{
m_editor->saveAs(m_playFile);
if (!m_editFile.isEmpty()) {
m_editor->saveAs(m_editFile);
}
QProcessEnvironment env = LiteApi::getCurrentEnvironment(m_liteApp);
QString go = FileUtil::lookPath("go",env,false);
QStringList args;
args << "run";
args << "goplay.go";
if (m_process->isRuning()) {
m_process->kill();
}
m_output->clear();
m_output->appendTag(QString("Run start ...\n\n"));
m_process->setEnvironment(env.toStringList());
m_process->start(go,args);
}
示例15: QProcess
void TgtProcessIntf::tgtMakeConnection()
{
std::shared_ptr<const TgtConnectionConfig> connectionConfig = std::dynamic_pointer_cast<const TgtConnectionConfig>(
_connectionConfig);
_proc = new QProcess(this);
connect(_proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readFromStdout()));
connect(_proc, SIGNAL(readyReadStandardError()), this, SLOT(readFromStderr()));
connect(_proc, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
connect(_proc, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processDone(int,QProcess::ExitStatus)));
_proc->setWorkingDirectory(connectionConfig->_workingDir.c_str());
QStringList args(connectionConfig->_args.c_str());
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("TERM", "xterm");
env.insert("COLORTERM", "gnome-terminal");
_proc->setProcessEnvironment(env);
_proc->start(connectionConfig->_program.c_str(), args);
_processWriterThread = TgtThread::create(boost::protect(std::bind(&TgtProcessIntf::writerThread, this)));
}