本文整理汇总了C++中QProcess::readLine方法的典型用法代码示例。如果您正苦于以下问题:C++ QProcess::readLine方法的具体用法?C++ QProcess::readLine怎么用?C++ QProcess::readLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QProcess
的用法示例。
在下文中一共展示了QProcess::readLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mystring
std::list<int> ProcessControl::getPidProcessByName(std::string name)
{
std::list<int> result;
qDebug() << "ProcessControl::getPidProcessByName: Begin:";
#ifndef WIN32
QProcess myprocess;
std::string command = std::string("ps -C ")+name+std::string(" -o pid --no-heading");
qDebug() << "ProcessControl::getPidProcessByName: comando solicitado:" << command.c_str();
myprocess.start(command.c_str());
if (!myprocess.waitForFinished()) return result;
while (!myprocess.atEnd())
{
char buf[16];
qint64 length = myprocess.readLine(buf,sizeof(buf));
if (length != -1)
{
QString mystring(buf);
result.push_back(mystring.toInt());
}
else break;
}
#else
DWORD aProcesses[1024], cbNeeded, cProcesses;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return result;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
for ( int i = 0 ; i < cProcesses; i++)
{
if (aProcesses[i] != 0)
{
std::wstring nombre = PrintProcessNameAndID( aProcesses[i] );
std::string temp;
std::copy(nombre.begin(), nombre.end(), std::back_inserter(temp));
qDebug() << "ProcessControl::getPidProcessByName: New pid name" << aProcesses[i] << temp.c_str();
if (QString(temp.c_str()).toLower()==QString(name.c_str()).toLower())
{
qDebug() << "ProcessControl::getPidProcessByName: found proccess";
result.push_back((int)aProcesses[i]);
}
}
}
#endif
return result;
}
示例2: checkEigenvalues
bool Features::checkEigenvalues(QTransform tr){
double eig1, eig2, eig3, minDist;
//qDebug() << "EIGENVALUES";
QString program = "./eig/eig.exe";
QStringList arguments;
arguments << QString::number(tr.m11());
arguments << QString::number(tr.m12());
arguments << QString::number(tr.m13());
arguments << QString::number(tr.m21());
arguments << QString::number(tr.m22());
arguments << QString::number(tr.m23());
arguments << QString::number(tr.m31());
arguments << QString::number(tr.m32());
arguments << QString::number(tr.m33());
QProcess *eig = new QProcess();
eig->start(program, arguments);
eig->waitForFinished();
QString line;
line = eig->readLine();
eig1 = line.left(line.indexOf('.') + 5).remove('\n').toDouble();
line = eig->readLine();
eig2 = line.left(line.indexOf('.') + 5).remove('\n').toDouble();
line = eig->readLine();
eig3 = line.left(line.indexOf('.') + 5).remove('\n').toDouble();
//qDebug() << "Eig1:" << eig1 << "| Eig2:" << eig2 << "| Eig3:" << eig3;
minDist = abs(eig1 - eig2);
if(abs(eig1 - eig3) < minDist) minDist = abs(eig1 - eig3);
if(abs(eig2 - eig3) < minDist) minDist = abs(eig2 - eig3);
//qDebug() << "MinDist:" << minDist;
return minDist <= 0.5;
}
示例3: test
bool PreloadCheck::test(const QString& symbol)
{
const QString fileName = findSharedObjectFile(symbol);
if (fileName.isEmpty()) {
setErrorString(QObject::tr("Cannot find file containing symbol: %1").arg(symbol));
return false;
}
if (!QFile(fileName).exists()) {
setErrorString(QObject::tr("Invalid shared object: %1").arg(fileName));
return false;
}
QStringList args;
args << "--relocs" << "--wide" << fileName;
QProcess proc;
proc.setProcessChannelMode(QProcess::MergedChannels);
proc.start("readelf", args, QIODevice::ReadOnly);
if (!proc.waitForFinished()) {
// TODO: Find out if we want to error out if 'readelf' is missing
// The question is: Do all (major) distributions ship binutils by default?
setErrorString(QObject::tr("Failed to run 'readelf' (binutils) binary: %1").arg(QString(proc.errorString())));
return false;
}
if (proc.exitCode() != 0) {
setErrorString(QObject::tr("Cannot read shared object: %1").arg(QString(proc.readAll())));
return false;
}
// Example line on x86_64: 00000049f3d8 054300000007 R_X86_64_JUMP_SLO 000000000016c930 qt_startup_hook + 0
// Example line on i386: 002e02f0 00034407 R_386_JUMP_SLOT 00181490 qt_startup_hook
QRegExp rx("^(?:[^ ]+\\s+){4}([^ ]+)(?:.*)$");
while(proc.canReadLine()) {
const QString line = proc.readLine().trimmed();
if (!rx.exactMatch(line))
continue;
const QString currentSymbol = rx.cap(1);
if (currentSymbol == symbol) {
qDebug() << "Found relocatable symbol in" << fileName << ":" << symbol;
setErrorString(QString());
return true;
}
}
setErrorString(QObject::tr("Symbol is not marked as relocatable: %1").arg(symbol));
return false;
}
示例4: getXCookie
void KCookie::getXCookie()
{
#if HAVE_X11
d->display = qgetenv("DISPLAY");
if (d->display.isEmpty()) {
// maybe we are on Wayland?
d->display = qgetenv("WAYLAND_DISPLAY");
if (!d->display.isEmpty()) {
// don't go into the xauth code path
return;
}
}
#else
d->display = qgetenv("QWS_DISPLAY");
#endif
if (d->display.isEmpty()) {
qCritical() << "[" << __FILE__ << ":" << __LINE__ << "] " << "$DISPLAY is not set.";
return;
}
#if HAVE_X11 // No need to mess with X Auth stuff
QByteArray disp = d->display;
if (disp.startsWith("localhost:")) { // krazy:exclude=strings
disp.remove(0, 9);
}
QProcess proc;
proc.start(QStringLiteral("xauth"), QStringList() << QStringLiteral("list") << QString::fromUtf8(disp));
if (!proc.waitForStarted()) {
qCritical() << "[" << __FILE__ << ":" << __LINE__ << "] " << "Could not run xauth.";
return;
}
proc.waitForReadyRead(100);
QByteArray output = proc.readLine().simplified();
if (output.isEmpty()) {
qWarning() << "No X authentication info set for display" << d->display;
return;
}
QList<QByteArray> lst = output.split(' ');
if (lst.count() != 3) {
qCritical() << "[" << __FILE__ << ":" << __LINE__ << "] " << "parse error.";
return;
}
d->displayAuth = (lst[1] + ' ' + lst[2]);
proc.waitForFinished(100); // give QProcess a chance to clean up gracefully
#endif
}
示例5: getVideo
void dialogCheckHardware::getVideo()
{
QString tmp, res, driver;
QProcess d;
d.start(QString("xdpyinfo"), QStringList());
while(d.state() == QProcess::Starting || d.state() == QProcess::Running) {
d.waitForFinished(200);
QCoreApplication::processEvents();
}
while (d.canReadLine()) {
tmp = d.readLine().simplified();
if ( tmp.indexOf("dimensions:") != -1 ) {
res = tmp.section(" ", 1, 1);
break;
}
}
// Figure out the driver
QFile file("/var/log/Xorg.0.log");
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&file);
while (!in.atEnd()) {
QString line = in.readLine();
if ( line.indexOf("Loading /usr/local/lib/xorg/modules/drivers/") != -1 ) {
QFileInfo fi(line);
driver = fi.fileName();
driver = driver.section("_", 0, 0);
break;
}
}
file.close();
}
if ( driver != "vesa" ) {
labelVideoDriverIcon->setPixmap(QPixmap(":/modules/images/ok.png"));
} else {
labelVideoDriverIcon->setPixmap(QPixmap(":/modules/images/failed.png"));
}
labelVideoDriverIcon->setScaledContents(true);
labelVideoDriver->setText(tr("Video driver:") + " (" + driver + ")" );
labelVideoResolution->setText(tr("Video resolution:") + " (" + res + ")" );
labelVideoResolutionIcon->setPixmap(QPixmap(":/modules/images/ok.png"));
labelVideoResolutionIcon->setScaledContents(true);
}
示例6: updateInitialDialog
void HgMergeDialog::updateInitialDialog()
{
HgWrapper *hgWrapper = HgWrapper::instance();
// update label - current branch
QString line("<b>parents:</b> ");
line += hgWrapper->getParentsOfHead();
m_currentChangeset->setText(line);
// update heads list
QProcess process;
process.setWorkingDirectory(hgWrapper->getBaseDir());
QStringList args;
args << QLatin1String("heads");
args << QLatin1String("--template");
args << QLatin1String("{rev}\n{node|short}\n{branch}\n"
"{author}\n{desc|firstline}\n");
process.start(QLatin1String("hg"), args);
m_commitInfoWidget->clear();
const int FINAL = 5;
char buffer[FINAL][1024];
int count = 0;
while (process.waitForReadyRead()) {
while (process.readLine(buffer[count], sizeof(buffer[count])) > 0) {
if (count == FINAL - 1) {
QString rev = QTextCodec::codecForLocale()->toUnicode(buffer[0]).trimmed();
QString changeset = QTextCodec::codecForLocale()->toUnicode(buffer[1]).trimmed();
QString branch = QTextCodec::codecForLocale()->toUnicode(buffer[2]).trimmed();
QString author = QTextCodec::codecForLocale()->toUnicode(buffer[3]).trimmed();
QString log = QTextCodec::codecForLocale()->toUnicode(buffer[4]).trimmed();
QListWidgetItem *item = new QListWidgetItem;
item->setData(Qt::DisplayRole, changeset);
item->setData(Qt::UserRole + 1, rev);
item->setData(Qt::UserRole + 2, branch);
item->setData(Qt::UserRole + 3, author);
item->setData(Qt::UserRole + 4, log);
m_commitInfoWidget->addItem(item);
}
count = (count + 1)%FINAL;
}
}
}
示例7: flushProcess
void VapoursynthSource::flushProcess(QProcess &processInput)
{
while(processInput.bytesAvailable() > 0)
{
log(tr("vpyp [info]: %1").arg(QString::fromUtf8(processInput.readLine()).simplified()));
}
if(processInput.exitCode() != EXIT_SUCCESS)
{
const int exitCode = processInput.exitCode();
log(tr("\nWARNING: Input process exited with error (code: %1), your encode might be *incomplete* !!!").arg(QString::number(exitCode)));
if((exitCode < 0) || (exitCode >= 32))
{
log(tr("\nIMPORTANT: The Vapoursynth process terminated abnormally. This means Vapoursynth or one of your Vapoursynth-Plugin's just crashed."));
}
}
}
示例8: flushProcess
void AvisynthSource::flushProcess(QProcess &processInput)
{
while(processInput.bytesAvailable() > 0)
{
log(tr("av2y [info]: %1").arg(QString::fromUtf8(processInput.readLine()).simplified()));
}
if(processInput.exitCode() != EXIT_SUCCESS)
{
const int exitCode = processInput.exitCode();
log(tr("\nWARNING: Input process exited with error (code: %1), your encode might be *incomplete* !!!").arg(QString::number(exitCode)));
if((exitCode < 0) || (exitCode >= 32))
{
log(tr("\nIMPORTANT: The Avs2YUV process terminated abnormally. This means Avisynth or one of your Avisynth-Plugin's just crashed."));
log(tr("IMPORTANT: Please fix your Avisynth script and try again! If you use Avisynth-MT, try using a *stable* Avisynth instead!"));
}
}
}
示例9: errorMessage
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));
}
}
示例10: 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");
}
示例11: sendBugReport
bool KBugReport::sendBugReport()
{
#ifndef EMSCRIPTEN
QString recipient ( d->m_aboutData ?
d->m_aboutData->bugAddress() :
QString::fromLatin1("[email protected]") );
QString command;
command = KStandardDirs::locate("exe", "ksendbugmail");
if (command.isEmpty())
command = KStandardDirs::findExe( QString::fromLatin1("ksendbugmail") );
QProcess proc;
QStringList args;
args << "--subject" << d->m_subject->text() << "--recipient" << recipient;
proc.start( command, args );
//kDebug() << command << args;
if (!proc.waitForStarted())
{
kError() << "Unable to open a pipe to " << command << endl;
return false;
}
proc.write( text().toUtf8() );
proc.closeWriteChannel();
proc.waitForFinished();
kDebug() << "kbugreport: sendbugmail exit, status " << proc.exitStatus() << " code " << proc.exitCode();
QByteArray line;
if (proc.exitStatus() == QProcess::NormalExit && proc.exitCode() != 0) {
// XXX not stderr?
while (!proc.atEnd())
line = proc.readLine();
d->lastError = QString::fromUtf8( line );
return false;
}
return true;
#else
kWarning() << "Bug report stuff not supported on Emscripten";
return false;
#endif
}
示例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;
}
示例13: sdkTargets
QStringList AndroidConfigurations::sdkTargets(int minApiLevel) const
{
QStringList targets;
QProcess proc;
proc.start(androidToolPath().toString(), QStringList() << QLatin1String("list") << QLatin1String("target")); // list avaialbe AVDs
if (!proc.waitForFinished(-1)) {
proc.terminate();
return targets;
}
while (proc.canReadLine()) {
const QString line = QString::fromLocal8Bit(proc.readLine().trimmed());
int index = line.indexOf(QLatin1String("\"android-"));
if (index == -1)
continue;
QString apiLevel = line.mid(index + 1, line.length() - index - 2);
if (apiLevel.mid(apiLevel.lastIndexOf(QLatin1Char('-')) + 1).toInt() >= minApiLevel)
targets.push_back(apiLevel);
}
return targets;
}
示例14: if
// Open the parent directory of the given path with a file manager and select
// (if possible) the item at the given path
void Utils::Misc::openFolderSelect(const QString &absolutePath)
{
const QString path = Utils::Fs::fromNativePath(absolutePath);
// If the item to select doesn't exist, try to open its parent
if (!QFileInfo(path).exists()) {
openPath(path.left(path.lastIndexOf("/")));
return;
}
#ifdef Q_OS_WIN
HRESULT hresult = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED);
PIDLIST_ABSOLUTE pidl = ::ILCreateFromPathW(reinterpret_cast<PCTSTR>(Utils::Fs::toNativePath(path).utf16()));
if (pidl) {
::SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0);
::ILFree(pidl);
}
if ((hresult == S_OK) || (hresult == S_FALSE))
::CoUninitialize();
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
QProcess proc;
proc.start("xdg-mime", QStringList() << "query" << "default" << "inode/directory");
proc.waitForFinished();
QString output = proc.readLine().simplified();
if ((output == "dolphin.desktop") || (output == "org.kde.dolphin.desktop"))
proc.startDetached("dolphin", QStringList() << "--select" << Utils::Fs::toNativePath(path));
else if ((output == "nautilus.desktop") || (output == "org.gnome.Nautilus.desktop")
|| (output == "nautilus-folder-handler.desktop"))
proc.startDetached("nautilus", QStringList() << "--no-desktop" << Utils::Fs::toNativePath(path));
else if (output == "nemo.desktop")
proc.startDetached("nemo", QStringList() << "--no-desktop" << Utils::Fs::toNativePath(path));
else if ((output == "konqueror.desktop") || (output == "kfmclient_dir.desktop"))
proc.startDetached("konqueror", QStringList() << "--select" << Utils::Fs::toNativePath(path));
else
// "caja" manager can't pinpoint the file, see: https://github.com/qbittorrent/qBittorrent/issues/5003
openPath(path.left(path.lastIndexOf("/")));
#else
openPath(path.left(path.lastIndexOf("/")));
#endif
}
示例15: qtCoreFromOtool
static QString qtCoreFromOtool(const QString &path)
{
QProcess proc;
proc.setProcessChannelMode(QProcess::SeparateChannels);
proc.setReadChannel(QProcess::StandardOutput);
proc.start("otool", QStringList() << "-L" << path);
proc.waitForFinished();
forever {
const QByteArray line = proc.readLine();
if (line.isEmpty())
break;
if (ProbeABIDetector::containsQtCore(line)) {
const int pos = line.lastIndexOf(" (");
if (pos <= 0)
continue;
return QString::fromLocal8Bit(line.left(pos).trimmed());
}
}
return QString();
}