本文整理汇总了C++中QProcess::bytesToWrite方法的典型用法代码示例。如果您正苦于以下问题:C++ QProcess::bytesToWrite方法的具体用法?C++ QProcess::bytesToWrite怎么用?C++ QProcess::bytesToWrite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QProcess
的用法示例。
在下文中一共展示了QProcess::bytesToWrite方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bytesToWrite
qint64 QProcessProto::bytesToWrite() const
{
QProcess *item = qscriptvalue_cast<QProcess*>(thisObject());
if (item)
return item->bytesToWrite();
return 0;
}
示例2: 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));
}
示例3: echoTest_performance
// Reading and writing to a process is not supported on Qt/CE
void tst_QProcess::echoTest_performance()
{
QProcess process;
process.start("testProcessLoopback/testProcessLoopback");
QByteArray array;
array.resize(1024 * 1024);
for (int j = 0; j < array.size(); ++j)
array[j] = 'a' + (j % 20);
QVERIFY(process.waitForStarted());
QTime stopWatch;
stopWatch.start();
qint64 totalBytes = 0;
QByteArray dump;
QSignalSpy readyReadSpy(&process, SIGNAL(readyRead()));
QVERIFY(readyReadSpy.isValid());
while (stopWatch.elapsed() < 2000) {
process.write(array);
while (process.bytesToWrite() > 0) {
int readCount = readyReadSpy.count();
QVERIFY(process.waitForBytesWritten(5000));
if (readyReadSpy.count() == readCount)
QVERIFY(process.waitForReadyRead(5000));
}
while (process.bytesAvailable() < array.size())
QVERIFY2(process.waitForReadyRead(5000), qPrintable(process.errorString()));
dump = process.readAll();
totalBytes += dump.size();
}
qDebug() << "Elapsed time:" << stopWatch.elapsed() << "ms;"
<< "transfer rate:" << totalBytes / (1048.576) / stopWatch.elapsed()
<< "MB/s";
for (int j = 0; j < array.size(); ++j)
QCOMPARE(char(dump.at(j)), char('a' + (j % 20)));
process.closeWriteChannel();
QVERIFY(process.waitForFinished());
}