开发者

dhclient output into a QlistWidget, realtime

I am using Ubuntu 10.10 with QT4.

i am wondering is it possible for a QlistWidget to show the output of Eg:

system("dhclient eth0");

then making qlistWidget shows the DHCPREQUEST/SHCPACK etc in real time?

So far i could only pipe the output of the command to a file,then get my program to read the file, which obviously does开发者_开发技巧 not show the DHCP packets exchanged at the moment.


Ok i solved it, here is a short examples of how i do it, i would only show my implementation

test::test()
{
    widget.setupUi(this);
    call();
    QObject::connect(&proc,SIGNAL(readyReadStandardOutput()),this,SLOT(stdOut()) );
    QObject::connect(&proc,SIGNAL(readyReadStandardError()),this,SLOT(stdErr()) ) ;
    QObject::connect(&proc,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(bye(int,QProcess::ExitStatus)) );

}
void test::call()
{
    proc.start("dhclient eth0");
}
void test::stdErr()
{
    QByteArray data = proc.readAllStandardError();
    widget.listWidget->addItem(QString(data));
}
void test::stdOut()
{
    QByteArray data = proc.readAllStandardOutput();
    widget.listWidget->addItem(QString(data));
}
void test::bye(int code,QProcess::ExitStatus exit)
{
    if(code ==0)
    {
        widget.listWidget->addItem("Done");
    }
}


Maybe this code sample will help you:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜