QT: how to show linux command output in text browser -
i want run linux command programmatically , show output in text browser. here code:
void mainwindow::on_pushbutton_clicked(){ qstring qstr; file *cl = popen("ifconfig eth0", "r"); char buf[1024]; while (fgets(buf, sizeof(buf), cl) != 0) { qstr = qstring::fromutf8(buf); ui->textbrowser->settext(qstr); } pclose(ls); }
but got nothing in text browser. if change qstr
in ui->textbrowser->settext(qstr);
arbitrary "string"
,it works fine. helps?! thanks.
in example popen use:
qstr += qstring::fromutf8(buf);
but better use qprocess. dynamic output use:
qprocess* ping_process = new qprocess(this); connect(ping_process, &qprocess::readyreadstandardoutput, [=] { ui->textbrowser->append(ping_process->readallstandardoutput()); }); ping_process->start("ping", qstringlist() << "8.8.8.8");
for use lambda not forget add in .pro file:
config += c++11
Comments
Post a Comment