QT错误转换非标量类型错误

时间:2014-06-26 09:16:25

标签: c++ qt

我正在捕捉QProcess的输出并将其与QRegularExpression匹配,但是会出现此错误....

任何提示??

/home/kshk/QT5/kshk-test1/main.cpp:33: error: conversion from 'std::string {aka std::basic_string<char>}' to non-scalar type 'QRegularExpressionMatch' requested
     QRegularExpressionMatch match = output.toStdString();


                                  ^

这是代码......

#include <QCoreApplication>
#include <QProcess>
#include <iostream>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#include <QRegularExpressionMatchIterator>
#include <QDebug>

using namespace std;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QString command = "bash -c \"netstat -i | grep ens33 | awk \'{print $3}\'\"";

    cout << "Hello Qt!" << endl;

    QProcess process;
    process.start(command);
    process.waitForFinished();

    QString output = process.readAllStandardOutput();

    //qDebug << output;

    cout << output.toStdString() << endl;

    QRegularExpression re("\\d\\d\\d\\d \\w\\w");
    //QRegularExpressionMatch match = re.match("This is a String - a string 1234 which you normalyy write everyday - pattern");

    //QRegularExpressionMatch match = re.match("This is 1234 al");
    QRegularExpressionMatch match = output.toStdString();

    if (match.hasMatch()){
        QString result = match.captured(0);
        cout << result.toStdString() << endl;
        cout << "string matched" << endl;
    }



    return a.exec();
}

0 个答案:

没有答案