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


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

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


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

示例1: testPass

void MainWindow::testPass()
{

  QString program = "sudo";
  QStringList arguments;
  arguments << "-S";
  arguments << "-k";
  arguments << "true";

  QProcess *tP = new QProcess(this);
  tP->setProcessChannelMode(QProcess::MergedChannels);
  tP->start(program, arguments);
  tP->write(passwordLineEdit->text().toLatin1() + "\n");
  tP->write(passwordLineEdit->text().toLatin1() + "\n");
  tP->write(passwordLineEdit->text().toLatin1() + "\n");
  while(tP->state() == QProcess::Starting || tP->state() == QProcess::Running ) {
     tP->waitForFinished(500);
     QCoreApplication::processEvents();
  }
  if ( tP->exitCode() != 0 )
  {
     QString tmp;
     tmp.setNum(tries-1);
     labelBadPW->setText(tr("Invalid Password! Tries Left: %1").arg(tmp) );
     tries--;
     if ( tries == 0 )
       exit(1);
     passwordLineEdit->setText("");
  } else {
     startSudo();
  }
}
开发者ID:rapenne-s,项目名称:pcbsd,代码行数:32,代码来源:mainwindow.cpp

示例2: main

int main(int argc, char** argv) {
  (void) argc;
  (void) argv;
  
  QProcess client;
  client.start("./client.elf", QStringList());
  myAssert(client.waitForStarted(), "Line " S__LINE__ ": The client could not be initialized properly.");
  char buffer[80];
  char buffer2[80];
  
  for(int i = 1 ; i <= 8 ; i++) {
    sprintf(buffer, "T %d 0\n", (i * 10) + 1);
    client.write(buffer);
    
    client.waitForReadyRead();
    for(int id = 1 ; id <= 8 ; id++) {
      if(i % id == 0) {
        sprintf(buffer, "D TESTER value %d", id);
        sprintf(buffer2, "Line " S__LINE__ ": Unexpected at i=%d and id=%d", i, id);
        myAssert(checkMsg(client, buffer), buffer2);
      }
    }
    
    myAssert(checkMsg(client, "T"), "Line " S__LINE__ ": The client thread did not send \"T\" as expected.");
  }
  
  client.write("S\n");
  myAssert(checkMsg(client, "S"), "Line " S__LINE__ ": The client thread did not send \"S\" as expected.");
  
  client.closeWriteChannel();
  myAssert(client.waitForFinished(), "Line " S__LINE__ ": The client did not close properly.");
  
  std::cout << "OK" << std::endl;
  return 0;
}
开发者ID:astralien3000,项目名称:aversive--,代码行数:35,代码来源:server.cpp

示例3: QString

QVector<TypeInfo> Process::getCompletions(const QString &filename, const QByteArray& ustart, const QByteArray& uend)
{
    QStringList args;
    args << "-f=csv" << "autocomplete" << filename << QString("c") + QString::number(ustart.length());

    QProcess p;
    p.start("gocode", args);

    if(!p.waitForStarted(TIMEOUT))
        return QVector<TypeInfo>();

    p.write(ustart);
    p.write(uend);
    p.closeWriteChannel();

    if(!p.waitForFinished(TIMEOUT))
        return QVector<TypeInfo>();

    QStringList lines = QString(p.readAllStandardOutput()).split("\n");
    QVector<TypeInfo> out;
    out.reserve(lines.size());

    TypeInfo info;

    for(int i = 0, e = lines.size(); i < e; ++i)
        if(info.parseString(lines[i]))
            out.push_back(info);

    return out;
}
开发者ID:nkovacs,项目名称:kgocode,代码行数:30,代码来源:process.cpp

示例4: ExecuteCmd

bool Pack::ExecuteCmd(QString exe, QStringList argument, QProcess &pprocess, QString workPath)
{
	QString enterPath = QStringLiteral("cd ") + "\"" + workPath + "\"" + QStringLiteral("\n");
	QString arg;
	arg.append(exe);
	for (QStringList::Iterator ite = argument.begin(); ite != argument.end(); ite++)
	{
		arg.append(" ");
		arg.append(*ite);		
	}
	arg.append("\n");
	pprocess.start("cmd");
	pprocess.waitForStarted();
	QTextCodec *gbk = QTextCodec::codecForName("GBK");
	QByteArray byteEnterPath = gbk->fromUnicode(enterPath.constData(), enterPath.length());
	QByteArray byteCommand = gbk->fromUnicode(arg.constData(), arg.length());
	char *charEnterPath = byteEnterPath.data();
	char *charCommand = byteCommand.data();
	pprocess.write(byteEnterPath);
	pprocess.write(charCommand);
	pprocess.closeWriteChannel();
	if (!pprocess.waitForFinished(1000 * 60 * 20)){
		return false;
	}
	return true;
	//mpprocess->setWorkingDirectory(workPath);
	//mpprocess->start(exe,argument);
}
开发者ID:langelee,项目名称:AutopackingAndroid,代码行数:28,代码来源:Pack.cpp

示例5: zip

bool zip()
{
//! [0]
    QProcess gzip;
    gzip.start("gzip", QStringList() << "-c");
    if (!gzip.waitForStarted())
        return false;

    gzip.write("Qt rocks!");
    gzip.closeWriteChannel();

    if (!gzip.waitForFinished())
        return false;

    QByteArray result = gzip.readAll();
//! [0]

    gzip.start("gzip", QStringList() << "-d" << "-c");
    gzip.write(result);
    gzip.closeWriteChannel();

    if (!gzip.waitForFinished())
        return false;

    qDebug("Result: %s", gzip.readAll().data());
    return true;
}
开发者ID:RSATom,项目名称:Qt,代码行数:27,代码来源:process.cpp

示例6: setUserPassword

bool SystemUtils::setUserPassword(const QString &password, const QString &user)
{
	QStringList args;
	if(password.isEmpty()) args << "--delete";
	const QString username = user.isEmpty() ? currentUser() : user;
	args << username;
	QProcess process;
	process.start(PASSWD_PROCESS, args);
	if(!process.waitForStarted(1000)) {
		process.kill();
		return false;
	}
	
	process.write(password.toUtf8());
	process.putChar(NEWLINE_CHAR);
	
	// Confirmation
	process.write(password.toUtf8());
	process.putChar(NEWLINE_CHAR);
	
	if(!process.waitForFinished(1000)) {
		process.kill();
		return false;
	}
	
	return process.exitCode() == 0;
}
开发者ID:kipr,项目名称:botui,代码行数:27,代码来源:SystemUtils.cpp

示例7: stream

QString ConnectionTester::Private::scutilHelper(const QByteArray &command, const QString &searchKey) const
{
    QString result;

    QProcess sc;
    QTextStream stream(&sc);
    sc.start("scutil");
    sc.waitForStarted();
    //sc.write("show State:/Network/Global/IPv4\n");
    sc.write(command);
    sc.write("\n");
    sc.waitForReadyRead();

    QString line = stream.readLine();

    while (!line.isEmpty())
    {
        QStringList parts = line.split(':');

        if (parts.size() == 2)
        {
            if (parts.at(0).trimmed() == searchKey)
            {
                result = parts.at(1).trimmed();
            }
        }

        line = stream.readLine();
    }

    sc.write("exit\n");
    sc.waitForFinished();

    return result;
}
开发者ID:glwu,项目名称:glimpse_client,代码行数:35,代码来源:connectiontester.cpp

示例8: QStringList

/// set the tooltable and start interpreting input from stdin. called from interpret()
bool g2m::startInterp(QProcess &tc) {
    if (!chooseToolTable())
        return false;
    // run:  rs274 file.ngc
    tc.start( interp , QStringList(file) );
    tc.write("3\n"); // "read tool file" command to rs274
    tc.write(tooltable.toAscii());
    tc.write("\n"); // "enter"
    tc.write("1\n"); // "start interpreting" command to rs274
    return true;
}
开发者ID:aewallin,项目名称:cutsim,代码行数:12,代码来源:g2m.cpp

示例9: 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));
}
开发者ID:MarianMMX,项目名称:MarianMMX,代码行数:53,代码来源:tst_qdbusxml2cpp.cpp

示例10: voice

TTSStatus TTSFestival::voice(QString text, QString wavfile, QString* errStr)
{
    qDebug() << "[Festival] Voicing " << text << "->" << wavfile;

    QString path = RbSettings::subValue("festival-client",
            RbSettings::TtsPath).toString();
    QString cmd = QString("%1 --server localhost --otype riff --ttw --withlisp"
            " --output \"%2\" --prolog \"%3\" - ").arg(path).arg(wavfile).arg(prologPath);
    qDebug() << "[Festival] Client cmd: " << cmd;

    QProcess clientProcess;
    clientProcess.start(cmd);
    clientProcess.write(QString("%1.\n").arg(text).toAscii());
    clientProcess.waitForBytesWritten();
    clientProcess.closeWriteChannel();
    clientProcess.waitForReadyRead();
    QString response = clientProcess.readAll();
    response = response.trimmed();
    if(!response.contains("Utterance"))
    {
        qDebug() << "[Festival] Could not voice string: " << response;
        *errStr = tr("engine could not voice string");
        return Warning;
        /* do not stop the voicing process because of a single string
        TODO: needs proper settings */
    }
    clientProcess.closeReadChannel(QProcess::StandardError);
    clientProcess.closeReadChannel(QProcess::StandardOutput);
    clientProcess.terminate();
    clientProcess.kill();

    return NoError;
}
开发者ID:a-martinez,项目名称:rockbox,代码行数:33,代码来源:ttsfestival.cpp

示例11: convert

// Slot of MainWindow
// For handle convert markdown to html
// Single receive from editor, when it text change
int MainWindow::convert()
{
    Ui_MainWindow *ui = this->ui;
    QProcess *myProcess = new QProcess();

    // Convert README.md to HTML
    QString program = "/home/ham/document/QT/MarkdownEditor/MarkdownEditor/mkd2html";
    QStringList arguments;

    // write editor content to README.md
    QString utf8_data = ui->editor->toPlainText();
    QByteArray byteArray=utf8_data.toLocal8Bit ();
    char *c=byteArray.data();

    // Setting args

    arguments << QStringList();
    // Exec
    myProcess->start(program, arguments);
    if (!myProcess->waitForStarted())
            return false;

    myProcess->write(c);
    myProcess->closeWriteChannel();

    if (!myProcess->waitForFinished())
            return false;
    QByteArray result = myProcess->readAll();

    qDebug() << result;
    ui->markdown_viewer->setHtml(result);


    return 0;
}
开发者ID:CarterTsai,项目名称:QMarkdown,代码行数:38,代码来源:mainwindow.cpp

示例12: sendEMail

bool Global::sendEMail(const QString subject, const QString to, const QString text, const QStringList attachments) {
    QStringList args;

    foreach (QString attachment, attachments)
        args << "-a" << attachment;

    args << "-s" << subject << to;

    QProcess process;
    process.start("mail", args);
    if (!process.waitForStarted())
        return false;

    QStringList lines = text.split("\n", QString::KeepEmptyParts);
    for (int i = 0; i < lines.size(); ++i) {
        process.write(QString(lines.at(i) + "\n").toUtf8());
    }

    process.closeWriteChannel();

    if (!process.waitForFinished())
        return false;
    if (process.exitCode() != 0)
        return false;

    return true;
}
开发者ID:Acidburn0zzz,项目名称:boxit,代码行数:27,代码来源:global.cpp

示例13: decrypt

Gpg::Decrypted Gpg::decrypt(QVector<QString> const &pInput)
{
    QProcess process;
    process.start(QStringLiteral("gpg"), QStringList() << QStringLiteral("--decrypt"));
    process.waitForStarted(-1);

    if (process.state() != QProcess::Running)
    {
        qWarning() << "Failed to launch GPG!";
        return Decrypted();
    }

    for (QString const &line : pInput)
    {
        process.write((line + '\n').toLatin1());
    }
    process.closeWriteChannel();

    process.waitForFinished(-1);
    if (process.exitCode() != 0)
    {
        qWarning() << "GPG terminated with exit code" << process.exitCode();
        return Decrypted();
    }

    return Decrypted(process.exitCode() == 0, process.readAllStandardOutput(), process.readAllStandardError());
}
开发者ID:RoffelKartoffel,项目名称:unenigmail,代码行数:27,代码来源:Gpg.cpp

示例14: 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;
}
开发者ID:anchowee,项目名称:QtCreator,代码行数:26,代码来源:uicodecompletionsupport.cpp

示例15: write

qint64 QProcessProto::write(const char *data, qint64 maxSize)
{
  QProcess *item = qscriptvalue_cast<QProcess*>(thisObject());
  if (item)
    return item->write(data, maxSize);
  return 0;
}
开发者ID:,项目名称:,代码行数:7,代码来源:


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