Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复 颜色对话框造成的内存泄漏问题 #166

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 6 additions & 25 deletions App/bll_polychat.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,18 @@ static QHostAddress getIPAddress()
{
QHostAddress ipAddress;
QList<QHostAddress> 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;
}
Expand Down
10 changes: 8 additions & 2 deletions App/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <QApplication>
#include <QTranslator>
#include <QHostInfo>

#include "uil_chatboxwidget.h"
#include "uil_loginwidget.h"
Expand All @@ -11,15 +12,20 @@
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[])
{
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: "<<localHostName;
qDebug() << "[Debug] QHostAddress::LocalHost: " << QHostAddress::LocalHost;
#endif

LoginWidget login;
login.show();
Expand Down
2 changes: 1 addition & 1 deletion App/uil_chatboxwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ChatBoxWidget::ChatBoxWidget(QWidget* parent, QString name, qint16 port)
/* 更改颜色 */
connect(ui->btnColor, &QToolButton::clicked,
this, [=](){
QColor color = QColorDialog::getColor(Qt::black); // getColor 参数中颜色是默认开启颜色对话框中的颜色
QColor color = QColorDialog::getColor(Qt::black, this); // getColor 参数中颜色是默认开启颜色对话框中的颜色
ui->msgTextEdit->setTextColor(color);
});

Expand Down
1 change: 1 addition & 0 deletions App/uil_loginwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Empty file added report.info
Empty file.
Loading