本文整理汇总了C++中QProcess::setReadChannelMode方法的典型用法代码示例。如果您正苦于以下问题:C++ QProcess::setReadChannelMode方法的具体用法?C++ QProcess::setReadChannelMode怎么用?C++ QProcess::setReadChannelMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QProcess
的用法示例。
在下文中一共展示了QProcess::setReadChannelMode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slotNotify
void SnoreToast::slotNotify(Notification notification)
{
QProcess *p = new QProcess(this);
p->setReadChannelMode(QProcess::MergedChannels);
connect(p,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotToastNotificationClosed(int,QProcess::ExitStatus)));
connect(qApp,SIGNAL(aboutToQuit()),p,SLOT(kill()));
QStringList arguements;
arguements << "-t"
<< Snore::toPlainText(notification.title())
<< "-m"
<< Snore::toPlainText(notification.text());
if(notification.icon().isValid())
{
arguements << "-p"
<< QDir::toNativeSeparators(notification.icon().localUrl());
}
arguements << "-w"
<< "-appID"
<< appId(notification.application())
<< "-id"
<< QString::number(notification.id());
if(notification.hints().value("silent",true).toBool())
{
arguements << "-silent";
}
snoreDebug( SNORE_DEBUG ) << "SnoreToast" << arguements;
p->start("SnoreToast", arguements);
p->setProperty("SNORE_NOTIFICATION_ID",notification.id());
}
示例2: execlocal
QString FoxGroundDocument::execlocal(const QString cmd, const QStringList args) {
QString debughere = cmd;
int success = -1;
debughere.append(" ");
debughere.append(args.join(" "));
//// console(QString("Fox:execlocal: %1").arg(debughere));
QString rec;
QProcess *process = new QProcess(NULL);
process->setReadChannelMode(QProcess::MergedChannels);
process->start(cmd, args, QIODevice::ReadOnly);
//// waitForFinished default int msecs = 30000 ok
if (!process->waitForFinished(80000)) {
success = -1;
} else {
success = 1;
rec = process->readAll();
}
if (success == 1) {
process->close();
return rec;
} else {
process->close();
return QString("ERROR: Time out by %1").arg(debughere);
}
}
示例3: run
/*!
\reimp
This class overrides QSerialIODevice::run() to run pppd directly on the
underlying device name so that it isn't necessary to create a pseudo-tty.
This is generally more efficient for running pppd.
*/
QProcess *QSerialPort::run( const QStringList& arguments,
bool addPPPdOptions )
{
if ( addPPPdOptions && d->isTty ) {
// Make sure we aren't using the device before handing it off to pppd.
if ( isOpen() )
close();
// Build a new argument list for pppd, with the device name in place.
QStringList newargs;
newargs << d->device;
newargs << QString::number( d->rate );
for ( int index = 1; index < arguments.size(); ++index )
newargs << arguments[index];
// Run the process. When it exits, open() will be called again.
QProcess *process = new QProcess();
process->setReadChannelMode( QProcess::ForwardedChannels );
connect( process, SIGNAL(stateChanged(QProcess::ProcessState)),
this, SLOT(pppdStateChanged(QProcess::ProcessState)) );
connect( process, SIGNAL(destroyed()), this, SLOT(pppdDestroyed()) );
process->start( arguments[0], newargs );
return process;
} else {
return QSerialIODevice::run( arguments, addPPPdOptions );
}
}
示例4: JavaVersion
double JavaVersion()
{
QProcess process;
QString Stversion;
bool ok;
double js_version = 0.00;
QRegExp regExp1(" (\\d+)\\.(\\d+).*");
process.setReadChannelMode(QProcess::MergedChannels);
process.start( "java" , QStringList() << "-version");
if (!process.waitForFinished()) {
return js_version;
} else {
QString pu = process.readAll();
/////QStringList line1 = pu.split("\n");
////////qDebug() << "### jsversion " << pu;
int pos1 = regExp1.indexIn(pu); /* only first line */
if (pos1 > 0) {
Stversion = QString("%1.%2").arg(regExp1.cap(1).toInt()).arg(regExp1.cap(2).toInt());
double js_version = Stversion.toDouble(&ok);
if (ok && js_version > 1) {
return js_version;
}
} else {
return js_version;
}
}
return js_version;
}
示例5: callGS
int callGS( const QStringList args )
{
const QString startnow = QDir::currentPath();
const QString GhostScriptPath = getGSDefaultExeName();
QDir::setCurrent(_GSCACHE_);
QString cmd1 = GhostScriptPath + " ";
cmd1 += args.join(" ");
int fax = -1;
#if defined Q_WS_MAC
fax = system(cmd1.toLocal8Bit());
QDir::setCurrent(startnow);
return fax;
#endif
QProcess *process = new QProcess(NULL);
process->setReadChannelMode(QProcess::MergedChannels);
process->start( GhostScriptPath , args , QIODevice::ReadOnly );
if (!process->waitForFinished()) {
fax = -1;
} else {
QString ghostcomment = process->readAll().trimmed();
//////qDebug() << "ghostcomment-> " << ghostcomment;
fax = 0;
}
QDir::setCurrent(startnow);
return fax;
}
示例6: 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();
}
}
}
示例7: getGSVersion
/* find gpl GhostScript version */
double getGSVersion()
{
QProcess process;
QString Stversion;
bool ok;
double GS_version = 0.00;
QRegExp regExp1(" (\\d+)\\.(\\d+).*");
process.setReadChannelMode(QProcess::MergedChannels);
process.start( getGSDefaultExeName() , QStringList() << "-v");
if (!process.waitForFinished()) {
return GS_version;
} else {
QString pu = process.readAll();
QStringList line1 = pu.split("\n");
int pos1 = regExp1.indexIn(line1.at(0)); /* only first line */
if (pos1 > 0) {
Stversion = QString("%1.%2").arg(regExp1.cap(1).toInt()).arg(regExp1.cap(2).toInt());
double GS_version = Stversion.toDouble(&ok);
if (ok && GS_version > 5) {
return GS_version;
}
} else {
return GS_version;
}
}
return GS_version;
}
示例8: execute
/*!
\overload
Starts the program \a program in a new process. \a program is a
single string of text containing both the program name and its
arguments. The arguments are separated by one or more spaces.
*/
int QProcess::execute(const QString &program)
{
QProcess process;
process.setReadChannelMode(ForwardedChannels);
process.start(program);
process.waitForFinished(-1);
return process.exitCode();
}
示例9: detachedShellCommand
/*!
Executes a command as a process
Output written to given socket as response.
*/
void ShellCommandService::detachedShellCommand(QString message, TasResponse& response)
{
TasLogger::logger()->debug("ShellCommandService::detachedShellCommand: " + message);
QProcess process;
process.setReadChannelMode(QProcess::MergedChannels);
process.setEnvironment(QProcess::systemEnvironment());
bool started = process.startDetached(message);
if(!started){
response.setErrorMessage("Failed to start process!");
}
}
示例10: shellCommand
/*!
Executes a command as a process
Output written to given socket as response.
*/
void ShellCommandService::shellCommand(QString message, TasResponse& response)
{
TasLogger::logger()->debug("ShellCommandService::shellCommand: " + message);
QProcess process;
process.setReadChannelMode(QProcess::MergedChannels);
process.setEnvironment(QProcess::systemEnvironment());
process.start(message);
process.closeWriteChannel();
process.waitForFinished(4000);
QByteArray output = process.readAll();
response.setData(output);
}
示例11: slotRegisterApplication
void SnoreToast::slotRegisterApplication(const Application &application)
{
if(!application.constHints().contains("windows_app_id"))
{
QProcess *p = new QProcess(this);
p->setReadChannelMode(QProcess::MergedChannels);
QStringList arguements;
arguements << "-install"
<< QString("SnoreNotify\\%1").arg(qApp->applicationName())
<< QDir::toNativeSeparators(qApp->applicationFilePath())
<< appId(application);
snoreDebug( SNORE_DEBUG ) << "SnoreToast" << arguements;
p->start("SnoreToast", arguements);
connect(p,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slotToastNotificationClosed(int,QProcess::ExitStatus)));
connect(qApp,SIGNAL(aboutToQuit()),p,SLOT(kill()));
}
示例12: qtVersionFromExec
static ProbeABI qtVersionFromExec(const QString &path)
{
ProbeABI abi;
// yep, you can actually execute QtCore.so...
QProcess proc;
proc.setReadChannelMode(QProcess::SeparateChannels);
proc.setReadChannel(QProcess::StandardOutput);
proc.start(path);
proc.waitForFinished();
const QByteArray line = proc.readLine();
const int pos = line.lastIndexOf(' ');
const QList<QByteArray> version = line.mid(pos).split('.');
if (version.size() < 3)
return abi;
abi.setQtVersion(version.at(0).toInt(), version.at(1).toInt());
return abi;
}
示例13: run
void MtrThread::run()
{
QMutexLocker locker(&mutex);
QStringList args;
args.append("--report-wide");
if(uudp)
args.append("-u");
args.append("-w");
args.append(url.host());
args.append("--report");
args.append("-c 30");
emit started();
qDebug() << "Starting MTR";
QProcess process;
process.setReadChannelMode(QProcess::MergedChannels);
process.closeWriteChannel();
process.start("mtr",args);
if(!process.waitForFinished(DEFAULT_MTRRUNTIME))
{
error = true;
process.kill();
process.waitForFinished(DEFAULT_MTRRUNTIME);
}
else
{
error = false;
}
data = process.readAll();
qDebug() << data;
qDebug() << "Finishing MTR: " << url;
emit finished();
}
示例14: runTask
void GenGraphForm::runTask()
{
QStringList argv = tasks.front();
tasks.pop_front();
exportButton->setText("&Kill");
QString cmd = argv.join(QString(" "));
std::cout << "STARTING TASK " << (const char*)cmd << std::endl;
#ifdef SOFA_QT4
QProcess* p = new QProcess(this);
QString program = argv.front();
argv.pop_front();
p->setReadChannelMode(QProcess::ForwardedChannels);
connect(p,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(taskFinished()));
p->start(program, argv);
#else
QProcess* p = new QProcess(argv, this);
p->setCommunication(0);
connect(p,SIGNAL(processExited()),this,SLOT(taskFinished()));
p->start();
#endif
currentTask = p;
}
示例15: execute
/*!
\param program The program to execute.
\param arguments The arguments to be passed to the program.
\return The exit code of the executed program.
Starts a program with arguments in a new process, waits for it to finish, and then returns
the exit code of the process. Any data the new process writes to the console is forwarded to
the calling process.
The environment and working directory are inherited by the calling process.
On Windows, arguments that contain spaces are wrapped in quotes.
*/
int TSystem::execute(const QString &program, const QStringList &arguments) const
{
QDEBUG_METHOD_NAME;
QProcess process;
// As seen in http://jira.codehaus.org/browse/IZPACK-20 and http://labs.trolltech.com/forums/topic/156, the method
// execute() from QProcess is not used.
qDebug() << TDebug::indentation << "Going to execute: " << program << " with arguments: " << arguments;
process.setReadChannelMode(QProcess::ForwardedChannels);
process.start(program, arguments);
process.waitForFinished(-1);
int exitCode = process.exitCode();
if (process.error() == QProcess::FailedToStart)
{
exitCode = -1;
}
return exitCode;
}