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