我正在Linux上编写程序。我想阅读tabconfig中的ifconfig和屏幕。我不知道该怎么做。
我找到了this example。我想升级。
我有很多错误
main.cpp: In function ‘int main(int, char**)’:
main.cpp:7:19: error: variable ‘QApplication app’ has initializer but incomplete type
/usr/include/qt4/QtGui/qtabwidget.h:167:14: error: ‘QTabBar* QTabWidget::tabBar() const’ is protected
main.cpp:21:14: error: within this context
main.cpp:21:15: error: invalid use of incomplete type ‘struct QTabBar’
/usr/include/qt4/QtGui/qtabwidget.h:56:7: error: forward declaration of ‘struct QTabBar’
main.cpp:21:33: error: incomplete type ‘QTabBar’ used in nested name specifier
main.cpp:21:63: error: ‘button3’ was not declared in this scope
main.cpp:23:1: error: ‘myprocess’ was not declared in this scope
main.cpp:25:11: error: ‘ps’ was not declared in this scope
main.cpp:26:9: error: ‘myTabWidget’ was not declared in this scope
make: *** [main.o] Error 1
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow *window = new QMainWindow();
window->setWindowTitle(QString::fromUtf8("MainWindow"));
window->resize(480, 480);
QWidget *centralWidget = new QWidget(window);
QTabWidget *tabs = new QTabWidget(centralWidget);
tabs->setFixedSize(440, 440);
tabs->addTab(new QWidget(),"TAB 1");
tabs->addTab(new QWidget(),"TAB 2");
tabs->addTab(new QWidget(),"TAB 3");
tabs->tabBar()->setTabButton(2, QTabBar::LeftSide,((QWidget*)(button3)));
QProcess myProcess;
myprocess.start("ifconfig");
if (myProcess.waitForStarted(-1)) {
while(ps.waitForReadyRead(-1)) {
myTabWidget.setText(1, myprocess.readAllStandardOutput());
}
}
window->setCentralWidget(centralWidget);
window->setCentralWidget(centralWidget);
window->show();
return app.exec();
}
最佳答案
您正在寻找QProcess和/或QtNetwork将此信息添加到选项卡小部件中。
...
tabs->tabBar()->setTabButton(2, QTabBar::LeftSide,((QWidget*)(button3)));
QProcess myProcess;
myprocess.start("ifconfig");
if (myProcess.waitForStarted(-1)) {
while(ps.waitForReadyRead(-1)) {
myTabWidget.setText(your_index, myprocess.readAllStandardOutput());
}
}
window->setCentralWidget(centralWidget);
...
话虽如此,您可以考虑将QtNetwork移植得更方便,因为“ ifconfig”在Windows上将无法运行,等等。您需要将其更改为ipconfig等。
为了公平起见,即使在Linux上,也应该查看“ ip”命令,而不要查看几乎没有维护的旧“ ifconfig”。
因此,您将使用适当的跨平台解决方案寻找QNetworkInterface和QHostAddress。这是一个简短的示例:
foreach(const QNetworkInterface &interface, QNetworkInterface::allInterfaces())
qDebug() << interface.hardwareAddress();
foreach(const QHostAdress &address, QNetworkInterface::allAddresses())
qDebug() << address.toString();
关于c++ - 如何从Linux应用程序发送ifconfig?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23441236/