本文整理汇总了C++中QProcess::errorString方法的典型用法代码示例。如果您正苦于以下问题:C++ QProcess::errorString方法的具体用法?C++ QProcess::errorString怎么用?C++ QProcess::errorString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QProcess
的用法示例。
在下文中一共展示了QProcess::errorString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exec
QString PHISSystemObj::exec( const QString &name, const QStringList &args, const QString &codecName )
{
QProcess proc;
_lastError=QString();
proc.start( name, args, QIODevice::ReadOnly );
if ( !proc.waitForStarted() ) {
QString err=tr( "Could not start process '%1' with arguments '%2': %3" )
.arg( name ).arg( args.join( QStringLiteral( " " ) ) ).arg( proc.errorString() );
PHIS_ERROR(err);
_lastError=proc.errorString();
_exitCode=proc.exitCode();
return QString();
}
if ( !proc.waitForFinished() ) {
QString err=tr( "Could not finish process '%1' with arguments '%2': %3" )
.arg( name ).arg( args.join( QStringLiteral( " " ) ) ).arg( proc.errorString() );
PHIS_ERROR(err);
_lastError=proc.errorString();
_exitCode=proc.exitCode();
return QString();
}
if ( proc.exitCode() ) {
QString err=tr( "Process '%1' exit code is '%2': %3" )
.arg( name ).arg( proc.exitCode() )
.arg( QString::fromUtf8( proc.readAllStandardError() ) );
PHIS_WARN(err);
_lastError=proc.errorString();
_exitCode=proc.exitCode();
}
QTextCodec *codec=QTextCodec::codecForName( codecName.toUtf8() );
if ( !codec ) codec=QTextCodec::codecForLocale();
return codec->toUnicode( proc.readAllStandardOutput() );
}
示例2: runApp
static Result runApp(const QString &execPath, const QStringList &args)
{
// QString outPipePath = FS::TmpFilePath("pipeOut");
QProcess app;
app.setProgram(execPath);
app.setArguments(args);
app.start();
if (!app.waitForStarted()) {
qWarning() << "Cmd Exec Failed:" << app.errorString();
return Result(Result::Failed, app.errorString(), "", app.program());
}
if (!app.waitForFinished(-1)) {
qWarning() << "waitForFinished Failed:" << app.errorString();
return Result(Result::Failed, app.errorString(), "", app.program());
}
auto standardError = app.readAllStandardError();
if (QProcess::NormalExit != app.exitStatus()) {
qWarning() << "exitStatus error:" << app.exitStatus() << standardError << app.program();
return Result(Result::Failed, standardError, "", app.program());
}
if (0 != app.exitCode()) {
qWarning() << "exitCode error:" << app.exitCode() << standardError << app.program();
return Result(Result::Failed, standardError, "", app.program());
}
Result rest(Result::Success, standardError, app.readAllStandardOutput());
return rest;
}
示例3: executeFile
QByteArray clientHandler::executeFile(QString file, QString argv)
{
QProcess pro;
QByteArray out;
QFile fs(this->workDir + file);
if (!fs.exists())
{
out = "Error: Resource "; out.append(file); out.append(" does not exist");
return out;
}
pro.start(this->workDir + file + " " + argv);
//start it
if (!pro.waitForStarted()){
out.append(pro.errorString());
return out;
}
//wait it to finished
if (!pro.waitForFinished()){
out.append(pro.errorString());
pro.close();
return out;
}
//read result
pro.waitForReadyRead();
out = pro.readAllStandardOutput();
pro.close();
return out;
}
示例4: execProcess
void ZHttpServer::execProcess(const QString &command, QTcpSocket *socket) const
{
qWarning() << "execProcess:" << command;
QProcess *process = new QProcess(const_cast<ZHttpServer*>(this));
connect(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error),
socket, [this, socket, process, command] {
qWarning() << QString("Exec \"%1\" failed:").arg(sysroot + "/" + command) << process->errorString();
socket->write(messagePackage("", "text/html", HttpInfo::OtherError, process->errorString()));
socket->close();
onProcessFinished(process);
});
connect(process, static_cast<void (QProcess::*)(int)>(&QProcess::finished),
socket, [this, socket, process] {
const QByteArray &message = process->exitCode() == 0
? process->readAllStandardOutput()
: process->readAllStandardError();
qWarning() << "execProcess finished, message:" << message;
socket->write(messagePackage(message));
socket->close();
onProcessFinished(process);
});
process->start(sysroot + "/" + command, QProcess::ReadOnly);
}
示例5: runProgram
PRL_RESULT CDspHaClusterHelper::runProgram(const QString & sPath, const QStringList & lstArgs, QProcess & proc)
{
WRITE_TRACE(DBG_INFO, "run %s %s", qPrintable(sPath), qPrintable(lstArgs.join(" ")));
proc.start(sPath, lstArgs);
if (!proc.waitForStarted(HAMAN_START_TMO)) {
WRITE_TRACE(DBG_FATAL, "Failed to run %s : %s",
QSTR2UTF8(sPath), QSTR2UTF8(proc.errorString()));
return PRL_ERR_CLUSTER_RESOURCE_ERROR;
}
if (!proc.waitForFinished(HAMAN_EXEC_TMO)) {
WRITE_TRACE(DBG_FATAL, "Failed to wait for finished %s : %s",
QSTR2UTF8(sPath), QSTR2UTF8(proc.errorString()));
proc.terminate();
return PRL_ERR_CLUSTER_RESOURCE_ERROR;
}
if (proc.exitCode()) {
WRITE_TRACE(DBG_FATAL, "%s failed : retcode : %d, stdout: [%s] stderr: [%s]",
QSTR2UTF8(sPath),
proc.exitCode(),
proc.readAllStandardOutput().constData(),
proc.readAllStandardError().constData()
);
return PRL_ERR_CLUSTER_RESOURCE_ERROR;
}
return PRL_ERR_SUCCESS;
}
示例6: QFETCH
void tst_qdbusxml2cpp::process()
{
QFETCH(QString, xmlSnippet);
QFETCH(QRegularExpression, interfaceSearch);
QFETCH(QRegularExpression, adaptorSearch);
QVERIFY2(interfaceSearch.isValid(), qPrintable(interfaceSearch.errorString()));
QVERIFY2(adaptorSearch.isValid(), qPrintable(adaptorSearch.errorString()));
// test both interface and adaptor generation
QFETCH_GLOBAL(int, outputMode);
QFETCH_GLOBAL(QString, commandLineArg);
// Run the tool
const QString binpath = QLibraryInfo::location(QLibraryInfo::BinariesPath);
const QString command = binpath + QLatin1String("/qdbusxml2cpp");
QProcess process;
process.start(command, QStringList() << commandLineArg << "-" << "-N");
QVERIFY2(process.waitForStarted(), qPrintable(process.errorString()));
// feed it our XML data
static const char xmlHeader[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE // \n is included
"<node>\n"
" <interface name=\"local.name.is.not.important\">\n"
" <!-- begin data -->\n";
static const char xmlFooter[] = "\n"
" <!-- end data -->\n"
" </interface>\n"
"</node>\n";
process.write(xmlHeader, int(sizeof xmlHeader) - 1);
process.write(xmlSnippet.toLatin1());
process.write(xmlFooter, int(sizeof xmlFooter) - 1);
while (process.bytesToWrite())
QVERIFY2(process.waitForBytesWritten(), qPrintable(process.errorString()));
// fprintf(stderr, "%s%s%s", xmlHeader, xmlSnippet.toLatin1().constData(), xmlFooter);
process.closeWriteChannel();
QVERIFY2(process.waitForFinished(), qPrintable(process.errorString()));
QByteArray errOutput = process.readAllStandardError();
QVERIFY2(errOutput.isEmpty(), errOutput);
QCOMPARE(process.exitCode(), 0);
QByteArray fullOutput = process.readAll();
QString output = stripHeader(QString::fromLatin1(fullOutput));
QVERIFY2(!output.isEmpty(), fullOutput);
if (outputMode == Interface)
QVERIFY2(output.count(interfaceSearch) == 1, qPrintable(interfaceSearch.pattern() + "\nin\n" + output));
else
QVERIFY2(output.count(adaptorSearch) == 1, qPrintable(adaptorSearch.pattern() + "\nin\n" + output));
}
示例7: qsystem
static QString qsystem(const QString &exe, const QStringList &args = QStringList())
{
QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);
p.start(exe, args);
if (!p.waitForStarted()) {
throw qbs::ErrorInfo(Tr::tr("Failed to start compiler '%1': %2")
.arg(exe, p.errorString()));
}
if (!p.waitForFinished() || p.exitCode() != 0)
throw qbs::ErrorInfo(Tr::tr("Failed to run compiler '%1': %2").arg(exe, p.errorString()));
return QString::fromLocal8Bit(p.readAll());
}
示例8: runProcess
void runProcess(const QStringList &commandLine, const QString &workingDir, QByteArray *output)
{
QStringList args = commandLine;
const QString command = args.takeFirst();
QProcess p;
if (!workingDir.isEmpty())
p.setWorkingDirectory(workingDir);
p.start(command, args);
if (!p.waitForStarted())
throw Exception(QString::fromLatin1("Process '%1' failed to start.").arg(command));
p.waitForFinished(-1);
if (p.exitStatus() != QProcess::NormalExit) {
throw Exception(QString::fromLatin1("Error running '%1': %2")
.arg(command, p.errorString()));
}
if (p.exitCode() != 0) {
QString errorString = QString::fromLatin1("Command '%1' finished with exit code %2.")
.arg(command).arg(p.exitCode());
const QByteArray stdErr = p.readAllStandardError();
if (!stdErr.isEmpty()) {
errorString += QString::fromLatin1("\nStandard error output was: '%1'")
.arg(QString::fromLocal8Bit(stdErr));
}
throw Exception(errorString);
}
if (output)
*output = p.readAllStandardOutput().trimmed();
}
示例9: generateKeys
void SshKeyCreationDialog::generateKeys()
{
if (SshSettings::keygenFilePath().isEmpty()) {
showError(tr("The ssh-keygen tool was not found."));
return;
}
if (QFileInfo::exists(privateKeyFilePath())) {
showError(tr("Refusing to overwrite existing private key file \"%1\".")
.arg(QDir::toNativeSeparators(privateKeyFilePath())));
return;
}
const QString keyTypeString = QLatin1String(m_ui->rsa->isChecked() ? "rsa": "ecdsa");
QApplication::setOverrideCursor(Qt::BusyCursor);
QProcess keygen;
const QStringList args{"-t", keyTypeString, "-b", m_ui->comboBox->currentText(),
"-N", QString(), "-f", privateKeyFilePath()};
QString errorMsg;
keygen.start(SshSettings::keygenFilePath().toString(), args);
keygen.closeWriteChannel();
if (!keygen.waitForStarted() || !keygen.waitForFinished())
errorMsg = keygen.errorString();
else if (keygen.exitCode() != 0)
errorMsg = QString::fromLocal8Bit(keygen.readAllStandardError());
if (!errorMsg.isEmpty()) {
showError(tr("The ssh-keygen tool at \"%1\" failed: %2")
.arg(SshSettings::keygenFilePath().toUserOutput(), errorMsg));
}
QApplication::restoreOverrideCursor();
accept();
}
示例10: startSession
bool InvokeCLI::startSession(QWidget* curr, QProcess* proc2)
{
parse retvals;
(void)(proc2);
QString program = CLI_PATH;
QStringList attributes;
attributes << "--start-session";
attributes << "-gui" << TEMP_FILE_NAME;
QProcess* proc = new QProcess(curr);
proc->start(program, attributes);
if(!proc->waitForFinished())
{
qDebug() << "Fail:\n"<< proc->errorString();
}
else
{
qDebug() << "Success:\n" << proc->readAll();
qDebug("Done!\n");
}
proc->close();
retvals=fileParse(curr);
if (retvals.sessionID >= 0)
{
this->sessionID = retvals.sessionID;
return true;
}
else
{
return false;
}
}
示例11: generateTestKeys
QString ItemEncryptedScriptable::generateTestKeys()
{
const KeyPairPaths keys;
for ( const auto &keyFileName : {keys.sec, keys.pub} ) {
if ( QFile::exists(keyFileName) && !QFile::remove(keyFileName) )
return QString("Failed to remove \"%1\"").arg(keys.sec);
}
QProcess process;
startGenerateKeysProcess(&process, true);
if ( !verifyProcess(&process) ) {
return QString("ItemEncrypt ERROR: %1; stderr: %2")
.arg( process.errorString(),
QString::fromUtf8(process.readAllStandardError()) );
}
const auto error = exportImportGpgKeys();
if ( !error.isEmpty() )
return error;
for ( const auto &keyFileName : {keys.sec, keys.pub} ) {
if ( !QFile::exists(keyFileName) )
return QString("Failed to create \"%1\"").arg(keys.sec);
}
return QString();
}
示例12: argBuild
void Arg_List::argBuild()
{
if(toPlainText() == "")
return;
QString argument = toPlainText();
QString fileName = stdValue.pathTemp + "/arg.txt", cmd;
QFile file(fileName);
if (file.open(QFile::WriteOnly | QFile::Truncate)) {
QTextStream out(&file);
out<<argument;
}
file.close();
if(stdValue.pathTrans == NULL)
cmd = "\"" + stdValue.pathTools + "/trans2.exe\" -c \"" + fileName + "\" err.log dbg.log";
else
cmd = "\"" + stdValue.pathTrans + "/trans2.exe\" -c \"" + fileName + "\" err.log dbg.log";
QFileInfo FI(fileName);
if(!FI.exists())
{
QMessageBox::warning(this,tr("Error"),"File not exist! " + fileName,QMessageBox::Yes);
return;
}
QProcess *Process = new QProcess(this);
Process->start(cmd);
if(!Process->waitForFinished() )
QMessageBox::warning(this,tr("Error"),Process->errorString() + "; " + cmd,QMessageBox::Yes);
}
示例13: createText
void MainWindow::createText() {
// Creates a new process to be called
QProcess *process = new QProcess;
#ifdef Q_WS_WIN
// Runs the CreateText.exe from debug folder
process->startDetached("CreateText");
// If the program runs, display a message saying it ran fine
if (process->waitForStarted() == true) {
qDebug() << "\nRunning CreateText";
}
#endif
#ifdef Q_WS_MACX
// Holds the path to the CreateText.exe
QString path = "open \"/Users/Teramino/Desktop/Qt/build-CreateText-Desktop_Qt_4_8_5-Debug/CreateText.app/Contents/MacOS/CreateText\"";
// Runs the CreateText.exe
process->start(path);
// If the program fails to start, display an error message and exit the program
if (process->waitForStarted() == false) {
qDebug() << "\nError starting CreateText";
qDebug() << process->errorString();
exit (-1);
}
// If the program runs, display a message saying it ran fine
if (process->waitForStarted() == true) {
qDebug() << "\nRunning CreateText";
}
#endif
}
示例14: on_startSim_clicked
void MainWindow::on_startSim_clicked()
{
QProcess *sim = new QProcess(this);
sim->startDetached("C:\\UDK\\UDK-2013-07\\USARRunMaps\\ExampleMap.bat");
//QThread::sleep(3);
qDebug()<<sim->errorString();
}
示例15: zipalign
bool Packer::zipalign(QString temp) const
{
const QString APK_SRC(temp + "/packed/temp-2.apk");
const QString APK_DST(temp + "/packed/temp-3.apk");
QProcess p;
p.start(QString("zipalign -f 4 \"%1\" \"%2\"").arg(APK_SRC, APK_DST));
if (p.waitForStarted(-1)) {
p.waitForFinished(-1);
if (p.exitCode() == 0) {
QFile::remove(APK_SRC);
return true;
}
else {
qDebug() << "Zipalign exit code:" << p.exitCode();
qDebug() << p.readAllStandardError().replace("\r\n", "\n");
}
}
else {
qDebug() << "Error starting Zipalign";
qDebug() << "Error:" << p.errorString();
}
// Something went wrong:
QFile::rename(APK_SRC, APK_DST);
return false;
}