From 0894ff10e4480db1d49d37d8e15ccac6d95e0901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B0=E7=B3=96=E9=9B=AA=E7=8B=B8?= Date: Wed, 15 May 2024 15:32:39 +0300 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E6=A1=86=E9=80=A0=E6=88=90=E7=9A=84=E5=86=85?= =?UTF-8?q?=E5=AD=98=E6=B3=84=E6=BC=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/bll_polychat.h | 31 ++++++------------------------- App/main.cpp | 10 ++++++++-- App/uil_chatboxwidget.cpp | 2 +- App/uil_loginwidget.cpp | 1 + report.info | 0 5 files changed, 16 insertions(+), 28 deletions(-) create mode 100644 report.info diff --git a/App/bll_polychat.h b/App/bll_polychat.h index bdb89be..1f7cf57 100644 --- a/App/bll_polychat.h +++ b/App/bll_polychat.h @@ -17,37 +17,18 @@ static QHostAddress getIPAddress() { QHostAddress ipAddress; QList ipAddressesList = QNetworkInterface::allAddresses(); - - // 优先寻找以192开头的IPv4地址 - for (const QHostAddress &address : ipAddressesList) + for (int i = 0; i < ipAddressesList.size(); ++i) { - if (address != QHostAddress::LocalHost && address.toIPv4Address()) + if (ipAddressesList.at(i) != QHostAddress::LocalHost + && ipAddressesList.at(i).toIPv4Address()) { - QString ipString = address.toString(); - if (ipString.startsWith("192")) - { - ipAddress = address; - break; - } - } - } - - // 如果没有找到以192开头的地址,再考虑其他IPv4地址 - if (ipAddress.isNull()) - { - for (const QHostAddress &address : ipAddressesList) { - if (address != QHostAddress::LocalHost && address.toIPv4Address()) - { - ipAddress = address; - break; - } + ipAddress = ipAddressesList.at(i); + break; } } - // 如果仍然没有找到,返回 localhost IPv4 地址 - if (ipAddress.isNull()) { + if (ipAddress.toString().isEmpty()) ipAddress = QHostAddress(QHostAddress::LocalHost); - } return ipAddress; } diff --git a/App/main.cpp b/App/main.cpp index f90f062..b1d2099 100644 --- a/App/main.cpp +++ b/App/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "uil_chatboxwidget.h" #include "uil_loginwidget.h" @@ -11,6 +12,8 @@ QString localUserName = ""; // User Name (will get in user login) QString localUserGroupNumber = ""; // Group number (will get in user login) QHostAddress localIpAddress = QHostAddress(); +QString localHostName = QHostInfo::localHostName(); + ChatList* chatList = nullptr; // Widget ChatList (Only one) int main(int argc, char *argv[]) @@ -18,8 +21,11 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); a.setWindowIcon(QIcon(":/icon/icons/logo_fox.png")); -// QString appDirPath = QCoreApplication::applicationDirPath(); //程序所在路径 -// qDebug() << appDirPath; +#if !QT_NO_DEBUG + qDebug() << "[Debug] appDirPath: " << QCoreApplication::applicationDirPath(); //程序所在路径 + qDebug() << "[Debug] localHostName: "<btnColor, &QToolButton::clicked, this, [=](){ - QColor color = QColorDialog::getColor(Qt::black); // getColor 参数中颜色是默认开启颜色对话框中的颜色 + QColor color = QColorDialog::getColor(Qt::black, this); // getColor 参数中颜色是默认开启颜色对话框中的颜色 ui->msgTextEdit->setTextColor(color); }); diff --git a/App/uil_loginwidget.cpp b/App/uil_loginwidget.cpp index 7ddc8db..5d26cf8 100644 --- a/App/uil_loginwidget.cpp +++ b/App/uil_loginwidget.cpp @@ -59,6 +59,7 @@ LoginWidget::LoginWidget(QWidget *parent) : connect(ui->btnLogin, &QPushButton::clicked, this, &LoginWidget::userLogin); + /* User checked button `about` */ connect(ui->btnInfo, &QPushButton::clicked, this, [=](){ QMessageBox::about(this, "About Polychat", diff --git a/report.info b/report.info new file mode 100644 index 0000000..e69de29