Skip to content

Commit d203998

Browse files
Merge pull request #166 from NekoSilverFox/MengJianing
修复 颜色对话框造成的内存泄漏问题
2 parents 6428f31 + 0894ff1 commit d203998

File tree

5 files changed

+16
-28
lines changed

5 files changed

+16
-28
lines changed

App/bll_polychat.h

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,18 @@ static QHostAddress getIPAddress()
1717
{
1818
QHostAddress ipAddress;
1919
QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
20-
21-
// 优先寻找以192开头的IPv4地址
22-
for (const QHostAddress &address : ipAddressesList)
20+
for (int i = 0; i < ipAddressesList.size(); ++i)
2321
{
24-
if (address != QHostAddress::LocalHost && address.toIPv4Address())
22+
if (ipAddressesList.at(i) != QHostAddress::LocalHost
23+
&& ipAddressesList.at(i).toIPv4Address())
2524
{
26-
QString ipString = address.toString();
27-
if (ipString.startsWith("192"))
28-
{
29-
ipAddress = address;
30-
break;
31-
}
32-
}
33-
}
34-
35-
// 如果没有找到以192开头的地址,再考虑其他IPv4地址
36-
if (ipAddress.isNull())
37-
{
38-
for (const QHostAddress &address : ipAddressesList) {
39-
if (address != QHostAddress::LocalHost && address.toIPv4Address())
40-
{
41-
ipAddress = address;
42-
break;
43-
}
25+
ipAddress = ipAddressesList.at(i);
26+
break;
4427
}
4528
}
4629

47-
// 如果仍然没有找到,返回 localhost IPv4 地址
48-
if (ipAddress.isNull()) {
30+
if (ipAddress.toString().isEmpty())
4931
ipAddress = QHostAddress(QHostAddress::LocalHost);
50-
}
5132

5233
return ipAddress;
5334
}

App/main.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <QApplication>
22
#include <QTranslator>
3+
#include <QHostInfo>
34

45
#include "uil_chatboxwidget.h"
56
#include "uil_loginwidget.h"
@@ -11,15 +12,20 @@
1112
QString localUserName = ""; // User Name (will get in user login)
1213
QString localUserGroupNumber = ""; // Group number (will get in user login)
1314
QHostAddress localIpAddress = QHostAddress();
15+
QString localHostName = QHostInfo::localHostName();
16+
1417
ChatList* chatList = nullptr; // Widget ChatList (Only one)
1518

1619
int main(int argc, char *argv[])
1720
{
1821
QApplication a(argc, argv);
1922
a.setWindowIcon(QIcon(":/icon/icons/logo_fox.png"));
2023

21-
// QString appDirPath = QCoreApplication::applicationDirPath(); //程序所在路径
22-
// qDebug() << appDirPath;
24+
#if !QT_NO_DEBUG
25+
qDebug() << "[Debug] appDirPath: " << QCoreApplication::applicationDirPath(); //程序所在路径
26+
qDebug() << "[Debug] localHostName: "<<localHostName;
27+
qDebug() << "[Debug] QHostAddress::LocalHost: " << QHostAddress::LocalHost;
28+
#endif
2329

2430
LoginWidget login;
2531
login.show();

App/uil_chatboxwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ ChatBoxWidget::ChatBoxWidget(QWidget* parent, QString name, qint16 port)
9797
/* 更改颜色 */
9898
connect(ui->btnColor, &QToolButton::clicked,
9999
this, [=](){
100-
QColor color = QColorDialog::getColor(Qt::black); // getColor 参数中颜色是默认开启颜色对话框中的颜色
100+
QColor color = QColorDialog::getColor(Qt::black, this); // getColor 参数中颜色是默认开启颜色对话框中的颜色
101101
ui->msgTextEdit->setTextColor(color);
102102
});
103103

App/uil_loginwidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ LoginWidget::LoginWidget(QWidget *parent) :
5959
connect(ui->btnLogin, &QPushButton::clicked,
6060
this, &LoginWidget::userLogin);
6161

62+
/* User checked button `about` */
6263
connect(ui->btnInfo, &QPushButton::clicked,
6364
this, [=](){
6465
QMessageBox::about(this, "About Polychat",

report.info

Whitespace-only changes.

0 commit comments

Comments
 (0)