大家好,今天主要给大家分享一下,如何使用Qt中的网络模块,编写实现TCP/IP客户端和服务器。接下来,可以通过QHostInfo 和 QNetworkInterface 类获取本地网络所有接口的信息。
第一:获取本机网络接口信息方法
对应头文件的实现方法:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <QTextBrowser>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QTimer>
/* 使用下面声明的WorkerThread线程类 */
class WorkerThread;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private:
/* 点击获取和清空文本按钮 */
QPushButton *pushB