#include <QProcess>
#include <QApplication>
#include <QByteArray>
#include <QList>
#include <QComboBox>
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
QComboBox *box = new QComboBox ;
box ->show();
QProcess *process = new QProcess;
process ->start("ifconfig");
QByteArray bal= process -> readAllStandardOutput ();
QList<QByteArray> ba = bal.split ('\n' );
QList<QByteArray>::const_iterator it = ba.constBegin();
QStringList strList;
while (it !=ba.constEnd())
{
if (it -> startsWith ("eth"))
{
//char *eh = qstrncpy (char *src , it, 4 );
QString st(*it);
QString str = st.left(4);
strList << str;
++it;
}
else if (it ->startsWith("wlan"))
{
// char *wl = qstrncpy(char *src2,it,5);
QString sd(*it);
QString str1 = sd.left(5);
strList << str1;
++it;
}
else { ++it;}
}
box ->addItems(strList);
return app.exec();
}
这是我写的源码,目的是从ifconfig命令得到的一大坨信息里,仅提取设备名称,如eth0,wlan0等,并把它放到QComboBox里,供用户选择,
但编译通过后,运行仅仅出现一个QComboBox,里面一项都没有,估计是前面的提取字符操作不应该放那,不知道app.exec具体做了些什么,高手帮我,谢谢