本文整理汇总了C++中QProcess::canReadLine方法的典型用法代码示例。如果您正苦于以下问题:C++ QProcess::canReadLine方法的具体用法?C++ QProcess::canReadLine怎么用?C++ QProcess::canReadLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QProcess
的用法示例。
在下文中一共展示了QProcess::canReadLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: outOfProcessUnconnectedClientServerTest
void tst_QUdpSocket::outOfProcessUnconnectedClientServerTest()
{
#if defined(Q_OS_WINCE)
QSKIP("This test depends on reading data from QProcess (not supported on Qt/WinCE.", SkipAll);
#endif
#if defined(QT_NO_PROCESS)
QSKIP("Qt was compiled with QT_NO_PROCESS", SkipAll);
#else
QProcess serverProcess;
serverProcess.start(QLatin1String("clientserver/clientserver server 1 1"),
QIODevice::ReadWrite | QIODevice::Text);
// Wait until the server has started and reports success.
while (!serverProcess.canReadLine())
QVERIFY(serverProcess.waitForReadyRead(3000));
QByteArray serverGreeting = serverProcess.readLine();
QVERIFY(serverGreeting != QByteArray("XXX\n"));
int serverPort = serverGreeting.trimmed().toInt();
QVERIFY(serverPort > 0 && serverPort < 65536);
QProcess clientProcess;
clientProcess.start(QString::fromLatin1("clientserver/clientserver unconnectedclient %1 %2")
.arg(QLatin1String("127.0.0.1")).arg(serverPort),
QIODevice::ReadWrite | QIODevice::Text);
// Wait until the server has started and reports success.
while (!clientProcess.canReadLine())
QVERIFY(clientProcess.waitForReadyRead(3000));
QByteArray clientGreeting = clientProcess.readLine();
QCOMPARE(clientGreeting, QByteArray("ok\n"));
// Let the client and server talk for 3 seconds
QTest::qWait(3000);
QStringList serverData = QString::fromLocal8Bit(serverProcess.readAll()).split("\n");
QStringList clientData = QString::fromLocal8Bit(clientProcess.readAll()).split("\n");
QVERIFY(serverData.size() > 5);
QVERIFY(clientData.size() > 5);
for (int i = 0; i < clientData.size() / 2; ++i) {
QCOMPARE(clientData.at(i * 2), QString("readData()"));
QCOMPARE(serverData.at(i * 3), QString("readData()"));
QString cdata = clientData.at(i * 2 + 1);
QString sdata = serverData.at(i * 3 + 1);
QVERIFY(cdata.startsWith(QLatin1String("got ")));
QCOMPARE(cdata.mid(4).trimmed().toInt(), sdata.mid(4).trimmed().toInt() * 2);
QVERIFY(serverData.at(i * 3 + 2).startsWith(QLatin1String("sending ")));
QCOMPARE(serverData.at(i * 3 + 2).trimmed().mid(8).toInt(),
sdata.mid(4).trimmed().toInt() * 2);
}
clientProcess.kill();
QVERIFY(clientProcess.waitForFinished());
serverProcess.kill();
QVERIFY(serverProcess.waitForFinished());
#endif
}
示例2: refreshStatus
void PFManagerDlg::refreshStatus(void)
{
//First check if the firewall is running
firewallRunning = false;
QProcess proc;
proc.start("sysctl net.inet.ip.fw.enable");
if(proc.waitForFinished() || proc.canReadLine()){
if (proc.canReadLine()){
QString line = proc.readLine();
if(line.section(":",1,1).simplified().toInt() ==1) { firewallRunning = true; }
}
}
//Enable/disable the UI elements
if (firewallRunning)
{
pbStart->setEnabled(false);
pbStop->setEnabled(true);
pbRestart->setEnabled(true);
}
else
{
pbStart->setEnabled(true);
pbStop->setEnabled(false);
pbRestart->setEnabled(false);
}
UpdatePortButtons();
}
示例3: available
QStringList CJoystick::available()
{
QStringList ret;
QProcess process;
process.start( "bash -c \"ls /dev/input/js*\"" /*, args*/ );
process.waitForFinished(10000);
while( process.canReadLine() )
{
QString line = process.readLine();
line.remove( "\n" );
line.remove( "\r" );
ret.append( line );
}
#if 0
QDir dir( "/dev/input/by-id" );
dir.setFilter( QDir::NoFilter );
qDebug( "dirName == %s", dir.path().toAscii().constData() );
QStringList list;
list.append( "*-joystick" );
ret = dir.entryList( list );
#endif
/*foreach( QString str, ret ) {
qDebug( "%s", str.toStdString().c_str() );
}*/
return ret;
}
示例4: processFinished
void DevicePluginWifiDetector::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
QProcess *p = static_cast<QProcess*>(sender());
p->deleteLater();
if (exitCode != 0 || exitStatus != QProcess::NormalExit) {
qCWarning(dcWifiDetector) << "error performing network scan:" << p->readAllStandardError();
return;
}
QList<Device*> watchedDevices = deviceManager()->findConfiguredDevices(supportedDevices().first().id());
if (watchedDevices.isEmpty()) {
return;
}
QStringList foundDevices;
while(p->canReadLine()) {
QString result = QString::fromLatin1(p->readLine());
if (result.startsWith("MAC Address:")) {
QStringList lineParts = result.split(' ');
if (lineParts.count() > 3) {
QString addr = lineParts.at(2);
foundDevices << addr.toLower();
}
}
}
foreach (Device *device, watchedDevices) {
bool wasInRange = device->stateValue(inRangeStateTypeId).toBool();
bool wasFound = foundDevices.contains(device->paramValue("mac").toString().toLower());
if (wasInRange != wasFound) {
device->setStateValue(inRangeStateTypeId, wasFound);
}
}
示例5: xvAdaptors
DeviceList DeviceInfo::xvAdaptors()
{
qDebug("DeviceInfo::xvAdaptors");
DeviceList l;
QRegExp rx_device("^.*Adaptor #([0-9]+): \"(.*)\"");
QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);
p.setEnvironment(QProcess::systemEnvironment() << "LC_ALL=C");
p.start("xvinfo");
if (p.waitForFinished()) {
QByteArray line;
while (p.canReadLine()) {
line = p.readLine();
qDebug("DeviceInfo::xvAdaptors: '%s'", line.constData());
if (rx_device.indexIn(line) > -1) {
QString id = rx_device.cap(1);
QString desc = rx_device.cap(2);
qDebug("DeviceInfo::xvAdaptors: found adaptor: '%s' '%s'", id.toUtf8().constData(), desc.toUtf8().constData());
l.append(DeviceData(id, desc));
}
}
} else {
qDebug("DeviceInfo::xvAdaptors: could not start xvinfo, error %d", p.error());
}
return l;
}
示例6: runCmd
QString MainWindow::runCmd(QString cmd, QStringList argv, int start, int length){
QProcess proc;
proc.start(cmd,argv);
QString res = "";
proc.waitForFinished();
int i=0;
while(proc.canReadLine()){
if(i>=start){
res = res + proc.readLine() + "\n";
}else{
proc.readLine();
}
if(i>=start+length){
break;
}
i+=1;
}
proc.kill();
res = res.trimmed();
return res;
}
示例7: retrieveDevices
DeviceList DeviceInfo::retrieveDevices(DeviceType type) {
qDebug("DeviceInfo::retrieveDevices: %d", type);
DeviceList l;
QRegExp rx_device("^(\\d+): (.*)");
if (QFile::exists("dxlist.exe")) {
QProcess p;
p.setProcessChannelMode( QProcess::MergedChannels );
QStringList arg;
if (type == Sound) arg << "-s"; else arg << "-d";
p.start("dxlist", arg);
if (p.waitForFinished()) {
QByteArray line;
while (p.canReadLine()) {
line = p.readLine().trimmed();
qDebug("DeviceInfo::retrieveDevices: '%s'", line.constData());
if ( rx_device.indexIn(line) > -1 ) {
int id = rx_device.cap(1).toInt();
QString desc = rx_device.cap(2);
qDebug("DeviceInfo::retrieveDevices: found device: '%d' '%s'", id, desc.toUtf8().constData());
l.append( DeviceData(id, desc) );
}
}
}
}
return l;
}
示例8: canReadLine
bool QProcessProto::canReadLine() const
{
QProcess *item = qscriptvalue_cast<QProcess*>(thisObject());
if (item)
return item->canReadLine();
return false;
}
示例9: getSound
void dialogCheckHardware::getSound()
{
QString tmp, snd;
// Figure out the driver
QProcess d;
d.start(QString("cat"), QStringList() << "/dev/sndstat");
while(d.state() == QProcess::Starting || d.state() == QProcess::Running) {
d.waitForFinished(200);
QCoreApplication::processEvents();
}
while (d.canReadLine()) {
tmp = d.readLine().simplified();
if ( tmp.indexOf("default") != -1 ) {
snd = tmp.section(":", 0, 0);
break;
}
}
if ( snd.isEmpty() )
{
labelSound->setText(tr("No sound detected"));
labelSoundIcon->setPixmap(QPixmap(":/modules/images/failed.png"));
labelSoundIcon->setScaledContents(true);
} else {
labelSound->setText(tr("Sound device:") + " (" + snd + ")" );
labelSoundIcon->setPixmap(QPixmap(":/modules/images/ok.png"));
labelSoundIcon->setScaledContents(true);
}
}
示例10: alsaDevices
DeviceList DeviceInfo::alsaDevices()
{
qDebug("DeviceInfo::alsaDevices");
DeviceList l;
QRegExp rx_device("^card\\s([0-9]+).*\\[(.*)\\],\\sdevice\\s([0-9]+):");
QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);
p.setEnvironment(QStringList() << "LC_ALL=C");
p.start("aplay", QStringList() << "-l");
if (p.waitForFinished()) {
QByteArray line;
while (p.canReadLine()) {
line = p.readLine();
qDebug("DeviceInfo::alsaDevices: '%s'", line.constData());
if (rx_device.indexIn(line) > -1) {
QString id = rx_device.cap(1);
id.append(".");
id.append(rx_device.cap(3));
QString desc = rx_device.cap(2);
qDebug("DeviceInfo::alsaDevices: found device: '%s' '%s'", id.toUtf8().constData(), desc.toUtf8().constData());
l.append(DeviceData(id, desc));
}
}
} else {
qDebug("DeviceInfo::alsaDevices: could not start aplay, error %d", p.error());
}
return l;
}
示例11: alsaDevices
TDeviceList TDeviceInfo::alsaDevices() {
Log4Qt::Logger* logger = Log4Qt::Logger::logger("Gui::TDeviceInfo");
logger->debug("alsaDevices");
TDeviceList l;
QRegExp rx_device("^card\\s([0-9]+).*\\[(.*)\\],\\sdevice\\s([0-9]+):");
QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);
p.setEnvironment(QStringList() << "LC_ALL=C");
p.start("aplay", QStringList() << "-l");
if (p.waitForFinished()) {
QByteArray line;
while (p.canReadLine()) {
line = p.readLine().trimmed();
if (rx_device.indexIn(line) >= 0) {
QString id = rx_device.cap(1);
id.append(".");
id.append(rx_device.cap(3));
QString desc = rx_device.cap(2);
logger->debug("alsaDevices: found device: '%1' '%2'", id, desc);
l.append(TDeviceData(id, desc));
}
}
} else {
logger->warn("alsaDevices: could not start aplay, error %1", p.error());
}
return l;
}
示例12: xvAdaptors
TDeviceList TDeviceInfo::xvAdaptors() {
Log4Qt::Logger* logger = Log4Qt::Logger::logger("Gui::TDeviceInfo");
logger->debug("xvAdaptors");
TDeviceList l;
QRegExp rx_device("^Adaptor #([0-9]+): \"(.*)\"");
QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);
p.setEnvironment(QProcess::systemEnvironment() << "LC_ALL=C");
p.start("xvinfo");
if (p.waitForFinished()) {
while (p.canReadLine()) {
QString s = QString::fromLocal8Bit(p.readLine()).trimmed();
logger->trace("xvAdaptors: line '%1'", s);
if (rx_device.indexIn(s) >= 0) {
QString id = rx_device.cap(1);
QString desc = rx_device.cap(2);
logger->debug("xvAdaptors: found adaptor: '" + id
+ " '" + desc + "'");
l.append(TDeviceData(id, desc));
}
}
} else {
logger->warn("xvAdaptors: could not start xvinfo, error %1", p.error());
}
return l;
}
示例13: watchStdErr
void OscapScannerBase::watchStdErr(QProcess& process)
{
process.setReadChannel(QProcess::StandardError);
QString stdErrOutput("");
// As readStdOut() is greedy and will continue reading for as long as there is output for it,
// by the time we come to handle sdterr output there may be multiple warning and/or error messages.
while (process.canReadLine())
{
// Trailing \n is returned by QProcess::readLine
stdErrOutput = process.readLine();
if (!stdErrOutput.isEmpty())
{
if (stdErrOutput.contains("WARNING: "))
{
QString guiMessage = guiFriendlyMessage(stdErrOutput);
emit warningMessage(QObject::tr(guiMessage.toUtf8().constData()));
}
// Openscap >= 1.2.11 (60fb9f0c98eee) sends this message through stderr
else if (stdErrOutput.contains(QRegExp("^Downloading: .+ \\.{3} \\w+\\n")))
{
emit infoMessage(stdErrOutput);
}
else
{
emit errorMessage(QObject::tr("The 'oscap' process has written the following content to stderr:\n"
"%1").arg(stdErrOutput));
}
}
}
}
示例14: getConflictDetailText
QString mainWin::getConflictDetailText() {
QStringList ConList = ConflictList.split(" ");
QStringList tmpDeps;
QString retText;
for (int i = 0; i < ConList.size(); ++i) {
QProcess p;
tmpDeps.clear();
if ( wDir.isEmpty() )
p.start("pkg", QStringList() << "rquery" << "%rn-%rv" << ConList.at(i));
else
p.start("chroot", QStringList() << wDir << "pkg" "rquery" << "%rn-%rv" << ConList.at(i) );
if(p.waitForFinished()) {
while (p.canReadLine()) {
tmpDeps << p.readLine().simplified();
}
}
retText+= ConList.at(i) + " " + tr("required by:") + "\n" + tmpDeps.join(" ");
}
return retText;
}
示例15: currentLocation
/**
* for now our data is just the MAC address of the default gateway
*/
NetworkLocation NetworkLocation::currentLocation()
{
QProcess ip;
ip.start("/sbin/ip", QStringList() << "route");
if (!ip.waitForStarted())
return NetworkLocation();
if (!ip.waitForFinished())
return NetworkLocation();
QByteArray gwIp;
while (ip.canReadLine()) {
QByteArray line = ip.readLine();
if (line.startsWith("default")) {
QList<QByteArray> parts = line.split(' ');
gwIp = parts[2];
break;
}
}
if (gwIp.isEmpty())
return NetworkLocation();
QProcess arp;
arp.start("/sbin/arp", QStringList() << "-a");
if (!arp.waitForStarted())
return NetworkLocation();
if (!arp.waitForFinished())
return NetworkLocation();
QByteArray gwMAC;
while (arp.canReadLine()) {
QByteArray line = arp.readLine();
if (line.contains(gwIp)) {
QList<QByteArray> parts = line.split(' ');
gwMAC = parts[3];
break;
}
}
if (gwMAC.isEmpty())
return NetworkLocation();
return NetworkLocation(gwMAC);
}