当前位置: 首页>>代码示例>>C++>>正文


C++ QProcess::setReadChannel方法代码示例

本文整理汇总了C++中QProcess::setReadChannel方法的典型用法代码示例。如果您正苦于以下问题:C++ QProcess::setReadChannel方法的具体用法?C++ QProcess::setReadChannel怎么用?C++ QProcess::setReadChannel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QProcess的用法示例。


在下文中一共展示了QProcess::setReadChannel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: executeFFMpeg

/** Runs the specified command (should be ffmpeg) and allows for progress feedback.
 *
 *  @param[in]  strCmd A string containing the command to execute and
 *              all of its arguments
 *  @param[out] progress A function that takes one float argument
 *              (the percentage of the ffmpeg operation complete) and
 *              may display the output to the user in any way it
 *              sees fit.
 *
 *  executeFFMpeg does not allow for writing direct input, the only
 *  input through the "-i" argument to specify input files on the disk.
 *
 *  @return Returns Status::OK if everything went well, and Status::FAIL
 *  and error is detected (usually a non-zero exit code for ffmpeg).
 */
Status MovieExporter::executeFFMpeg(QString strCmd, std::function<void(float)> progress)
{
    qDebug() << strCmd;

    QProcess ffmpeg;
    ffmpeg.setReadChannel(QProcess::StandardOutput);
    // FFmpeg writes to stderr only for some reason, so we just read both channels together
    ffmpeg.setProcessChannelMode(QProcess::MergedChannels);
    ffmpeg.start(strCmd);
    if (ffmpeg.waitForStarted() == true)
    {
        while(ffmpeg.state() == QProcess::Running)
        {
            if(!ffmpeg.waitForReadyRead()) break;

            QString output(ffmpeg.readAll());
            QStringList sList = output.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
            for (const QString& s : sList)
            {
                qDebug() << "[stdout]" << s;
            }

            if(output.startsWith("frame="))
            {
                QString frame = output.mid(6, output.indexOf(' '));

                progress(frame.toInt() / static_cast<float>(mDesc.endFrame - mDesc.startFrame));
            }
        }

        QString output(ffmpeg.readAll());
        QStringList sList = output.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
        for (const QString& s : sList)
        {
            qDebug() << "[ffmpeg]" << s;
        }

        if(ffmpeg.exitStatus() != QProcess::NormalExit)
        {
            qDebug() << "ERROR: FFmpeg crashed";
            return Status::FAIL;
        }
    }
    else
    {
        qDebug() << "ERROR: Could not execute FFmpeg.";
        return Status::FAIL;
    }
    return Status::OK;
}
开发者ID:chchwy,项目名称:pencil2d,代码行数:65,代码来源:movieexporter.cpp

示例2: qc_run_program_or_command

int qc_run_program_or_command(const QString &prog, const QStringList &args, const QString &command, QByteArray *out, bool showOutput)
{
	if(out)
		out->clear();

	QProcess process;
	process.setReadChannel(QProcess::StandardOutput);

	if(!prog.isEmpty())
		process.start(prog, args);
	else if(!command.isEmpty())
		process.start(command);
	else
		return -1;

	if(!process.waitForStarted(-1))
		return -1;

	QByteArray buf;

	while(process.waitForReadyRead(-1))
	{
		buf = process.readAllStandardOutput();
		if(out)
			out->append(buf);
		if(showOutput)
			fprintf(stdout, "%s", buf.data());

		buf = process.readAllStandardError();
		if(showOutput)
			fprintf(stderr, "%s", buf.data());
	}

	buf = process.readAllStandardError();
	if(showOutput)
		fprintf(stderr, "%s", buf.data());

	// calling waitForReadyRead will cause the process to eventually be
	//   marked as finished, so we should not need to separately call
	//   waitForFinished. however, we will do it anyway just to be safe.
	//   we won't check the return value since false could still mean
	//   success (if the process had already been marked as finished).
	process.waitForFinished(-1);

	if(process.exitStatus() != QProcess::NormalExit)
		return -1;

	return process.exitCode();
}
开发者ID:eta-im-dev,项目名称:qconf,代码行数:49,代码来源:conf4.cpp

示例3: ready

void Tmpl::ready()
{
    for (QList<TmplExpand>::iterator it = tmpls.begin(); it != tmpls.end(); ++it){
        QProcess *p = it->process;
        if (p && p->state() == QProcess::NotRunning){
            if (p->exitStatus() == QProcess::NormalExit){
                it->bReady = true;
                p->setReadChannel(QProcess::StandardOutput);
                it->res += QString::fromLocal8Bit(p->readAll());
                QTimer::singleShot(0, this, SLOT(clear()));
                return;
            }
        }
    }
}
开发者ID:,项目名称:,代码行数:15,代码来源:

示例4: startProcess

bool AbstractTool::startProcess(QProcess &process, const QString &program, const QStringList &args, bool mergeChannels)
{
	QMutexLocker lock(&s_mutexStartProcess);
	log(commandline2string(program, args) + "\n");

	process.setWorkingDirectory(QDir::tempPath());

	if(mergeChannels)
	{
		process.setProcessChannelMode(QProcess::MergedChannels);
		process.setReadChannel(QProcess::StandardOutput);
	}
	else
	{
		process.setProcessChannelMode(QProcess::SeparateChannels);
		process.setReadChannel(QProcess::StandardError);
	}

	process.start(program, args);
	
	if(process.waitForStarted())
	{
		m_jobObject->addProcessToJob(&process);
		MUtils::OS::change_process_priority(&process, m_preferences->getProcessPriority());
		lock.unlock();
		return true;
	}

	log("Process creation has failed :-(");
	QString errorMsg= process.errorString().trimmed();
	if(!errorMsg.isEmpty()) log(errorMsg);

	process.kill();
	process.waitForFinished(-1);
	return false;
}
开发者ID:kalergman,项目名称:Simple-x264-Launcher,代码行数:36,代码来源:tool_abstract.cpp

示例5: execute

QString execute(QString command, QStringList arguments, bool mergeErrorStream)
{
    QProcess process;
    process.setReadChannel(QProcess::StandardOutput);
    if (mergeErrorStream)
        process.setProcessChannelMode(QProcess::MergedChannels);
    process.start(command, arguments);
    if (!process.waitForStarted())
        return QString();
    if (!process.waitForFinished())
        return QString();

    QByteArray result = process.readAll();
    return QString::fromUtf8(result);
}
开发者ID:Tofee,项目名称:space-inspector,代码行数:15,代码来源:globals.cpp

示例6: QString

QString Nepomuk2::OfficeExtractor::textFromFile(const QUrl &fileUrl, const QString &command, QStringList &arguments)
{
    arguments << fileUrl.toLocalFile();

    // Start a process and read its standard output
    QProcess process;

    process.setReadChannel(QProcess::StandardOutput);
    process.start(command, arguments, QIODevice::ReadOnly);
    process.waitForFinished();

    if (process.exitStatus() != QProcess::NormalExit || process.exitCode() != 0)
        return QString();
    else
        return QString::fromUtf8(process.readAll());
}
开发者ID:KDE,项目名称:nepomuk-core,代码行数:16,代码来源:officeextractor.cpp

示例7: ReadFromFile

bool PackageInfo::ReadFromFile(QString sName)
{
	QProcess procInfo;

	procInfo.setReadChannel(QProcess::StandardOutput);
	procInfo.start("dpkg-deb", QStringList() << "-f" << sName);
	procInfo.waitForFinished(3000);

	if (procInfo.exitStatus() == QProcess::NormalExit) {
		m_qsFilename = sName;
		return ParsePackageInfo(&procInfo);
	}
	else {
		qDebug() << procInfo.readAllStandardError();
	}

	return false;
}
开发者ID:jpoirier,项目名称:x-gauges,代码行数:18,代码来源:SoftwarePackage.cpp

示例8: watchStdErr

void OscapScannerBase::watchStdErr(QProcess& process)
{
    process.setReadChannel(QProcess::StandardError);

    QString errorMessage("");

    while (process.canReadLine())
    {
        // Trailing \n is returned by QProcess::readLine
        errorMessage += process.readLine();
    }

    if (!errorMessage.isEmpty())
    {
        emit warningMessage(QObject::tr("The 'oscap' process has written the following content to stderr:\n"
                                        "%1").arg(errorMessage));
    }
}
开发者ID:finkr,项目名称:scap-workbench,代码行数:18,代码来源:OscapScannerBase.cpp

示例9: getVersion

QString VersionChecker::getVersion()
{
	QProcess process;
	process.start(m_app, QStringList() << "--version");

	process.setReadChannel(QProcess::StandardOutput);
	if (process.waitForStarted() && process.waitForFinished())
	{
		QRegExp rx(VERSION_REGEX);
		QString text = process.readLine();
		if (rx.indexIn(text) != -1)
		{
			return rx.cap(1);
		}
	}

	return tr("Unknown");
}
开发者ID:neilmayhew,项目名称:synergy,代码行数:18,代码来源:VersionChecker.cpp

示例10: on_Create_clicked

// when create is pressed
void MainWindow::on_Create_clicked()
{
    // declarations
    QMessageBox Finished;
    QString Message;
    QProcess bximage;
    QStringList arguments;
    int size2;
    bool ok;
    size_t BufSize = 1024;
    char buf[BufSize];
    QString currentPath;

    // make size argument
    size2 = Size.toInt(&ok, 10);
    snprintf(buf, BufSize, "-size=%i", size2);
    Size = QString::fromAscii(buf);

    // put bximage arugments in arguments
    arguments << type << format;
    arguments << Size << "-q";
    arguments << path;

    // print arguments
    for(int count = 0; count < 5; count++)
        qDebug() << arguments[count];

    // print current path
    currentPath = QDir::currentPath();
    qDebug() << currentPath;

    // start bximage
    bximage.setReadChannel(QProcess::StandardOutput);
    bximage.setWorkingDirectory(QString(QDir::currentPath()));
    bximage.start("bximage", arguments);
    bximage.waitForStarted(-1);

    // make messagebox
    Message = path + QString(" has been created");
    Finished.setWindowTitle("Finished");
    Finished.setText(Message);
    Finished.setIcon(QMessageBox::Information);
    Finished.exec();
}
开发者ID:ioshomebrew,项目名称:bxUI,代码行数:45,代码来源:mainwindow.cpp

示例11: lamexp_init_process

/*
 * Setup QPorcess object
 */
void lamexp_init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir)
{
	//Environment variable names
	static const char *const s_envvar_names_temp[] =
	{
		"TEMP", "TMP", "TMPDIR", "HOME", "USERPROFILE", "HOMEPATH", NULL
	};
	static const char *const s_envvar_names_remove[] =
	{
		"WGETRC", "SYSTEM_WGETRC", "HTTP_PROXY", "FTP_PROXY", "NO_PROXY", "GNUPGHOME", "LC_ALL", "LC_COLLATE", "LC_CTYPE", "LC_MESSAGES", "LC_MONETARY", "LC_NUMERIC", "LC_TIME", "LANG", NULL
	};

	//Initialize environment
	QProcessEnvironment env = process.processEnvironment();
	if(env.isEmpty()) env = QProcessEnvironment::systemEnvironment();

	//Clean a number of enviroment variables that might affect our tools
	for(size_t i = 0; s_envvar_names_remove[i]; i++)
	{
		env.remove(QString::fromLatin1(s_envvar_names_remove[i]));
		env.remove(QString::fromLatin1(s_envvar_names_remove[i]).toLower());
	}

	const QString tempDir = QDir::toNativeSeparators(lamexp_temp_folder2());

	//Replace TEMP directory in environment
	if(bReplaceTempDir)
	{
		for(size_t i = 0; s_envvar_names_temp[i]; i++)
		{
			env.insert(s_envvar_names_temp[i], tempDir);
		}
	}

	//Setup PATH variable
	const QString path = env.value("PATH", QString()).trimmed();
	env.insert("PATH", path.isEmpty() ? tempDir : QString("%1;%2").arg(tempDir, path));
	
	//Setup QPorcess object
	process.setWorkingDirectory(wokringDir);
	process.setProcessChannelMode(QProcess::MergedChannels);
	process.setReadChannel(QProcess::StandardOutput);
	process.setProcessEnvironment(env);
}
开发者ID:BackupTheBerlios,项目名称:lamexp,代码行数:47,代码来源:Global_Utils.cpp

示例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;
}
开发者ID:xhaakon,项目名称:GammaRay,代码行数:20,代码来源:probeabidetector_elf.cpp

示例13: request

// we use syntool to authenticate because Qt's http library is very
// unreliable, and since we're writing platform specific code, use the
// synergy code since there we can use integ tests.
QString PremiumAuth::request(const QString& email, const QString& password)
{
	QString program(QCoreApplication::applicationDirPath() + "/syntool");
	QStringList args("--premium-auth");

	QProcess process;
	process.setReadChannel(QProcess::StandardOutput);
	process.start(program, args);
	bool success = process.waitForStarted();

	QString out, error;
	if (success)
	{
		// hash password in case it contains interesting chars.
		QString credentials(email + ":" + hash(password) + "\n");
		process.write(credentials.toStdString().c_str());

		if (process.waitForFinished()) {
			out = process.readAllStandardOutput();
			error = process.readAllStandardError();
		}
	}

	out = out.trimmed();
	error = error.trimmed();

	if (out.isEmpty() ||
		!error.isEmpty() ||
		!success ||
		process.exitCode() != 0)
	{
		throw std::runtime_error(
			QString("Code: %1\nError: %2")
				.arg(process.exitCode())
				.arg(error.isEmpty() ? "Unknown" : error)
				.toStdString());
	}

	return out;
}
开发者ID:BogdanLivadariu,项目名称:synergy,代码行数:43,代码来源:PremiumAuth.cpp

示例14: makeShader

void makeShader() {
       QStringList files;
       files << "i420_to_rgb_simple.cpp" << "i420_to_rgb_filter.cpp" << "i420_to_rgb_kernel.cpp";
       for (int i=0; i<files.size(); ++i) {
	       qDebug() << "Interpret" << files[i];
	       QProcess proc;
	       proc.setReadChannel(QProcess::StandardOutput);
	       QStringList args;
	       args << "-E" << files[i];
	       proc.start("g++", args, QProcess::ReadOnly);
	       const bool ready = proc.waitForReadyRead();
	       Q_ASSERT(ready);
	       QList<QByteArray> lines = proc.readAllStandardOutput().split('\n');
	       QByteArray output;
	       for (int j=0; j<lines.size(); ++j) {
		       if (!lines[j].startsWith('#')) {
			       output += lines[j];
			       output += '\n';
		       }
	       }

	       if (!proc.waitForFinished())
		       proc.kill();
	       Interpreter interpreter;
	       if (!interpreter.interpret(output))
		       qFatal("Interpreter Error: %s", qPrintable(interpreter.errorMessage()));
	       const QFileInfo info(files[i]);
	       const QString base = info.completeBaseName();
	       QFile fp(base + ".fp");
	       fp.open(QFile::WriteOnly | QFile::Truncate);
	       Q_ASSERT(fp.isOpen());
	       fp.write(interpreter.code());
	       fp.close();
	       args.clear();
	       args << "-i" << (base + ".fp") << ("../" + base + ".hpp");
	       proc.start("xxd", args, QProcess::ReadOnly);
	       if (!proc.waitForFinished())
		       proc.kill();
       }
}
开发者ID:kleopatra999,项目名称:cmplayer-kldp.net,代码行数:40,代码来源:main.cpp

示例15: upload

void PlatformPicaxe::upload(QWidget *source, const QString &port, const QString &board, const QString &fileLocation)
{
    // see http://www.picaxe.com/docs/beta_compiler.pdf
    QProcess * process = new QProcess(this);
    process->setProcessChannelMode(QProcess::MergedChannels);
    process->setReadChannel(QProcess::StandardOutput);

    connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), source, SLOT(programProcessFinished(int, QProcess::ExitStatus)));
    connect(process, SIGNAL(readyReadStandardOutput()), source, SLOT(programProcessReadyRead()));

    QFileInfo cmdFileInfo(getCommandLocation());
    QString cmd(cmdFileInfo.absoluteDir().absolutePath().append("/").append(getBoards().value(board)));

    QStringList args;
    args.append(QString("-c%1").arg(port));
    args.append(fileLocation);

    ProgramTab *tab = qobject_cast<ProgramTab *>(source);
    if (tab)
        tab->appendToConsole(tr("Running %1 %2").arg(cmd).arg(args.join(" ")));
    process->start(cmd, args);
}
开发者ID:BrainsoftLtd,项目名称:fritzing-app,代码行数:22,代码来源:platformpicaxe.cpp


注:本文中的QProcess::setReadChannel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。