Merged
Conversation
将 move() 调用移到 show() 之前,避免窗口先显示在错误位置再移动导致的闪烁, 同时确保在 setJsonData() 完成布局计算后再获取窗口尺寸。 Log: 修复窗口位置显示不正确的问题 Bug: https://pms.uniontech.com/bug-view-325485.html
|
TAG Bot TAG: 5.5.5 |
deepin pr auto review我来对这个 Git diff 进行详细审查:
a) 在 newClientProcess 函数中: localSocket->waitForBytesWritten(1000);建议:
b) 在 processArgs 函数中: w->hide();
QApplication::processEvents();
w->adjustSize();建议:
a) 在 readData 函数中: for (const QByteArray &data : message.split('\0')) {
QString str = QString::fromLocal8Bit(data);
if (!str.isEmpty()) {
list << str;
}
}建议:
a) 在 newClientProcess 函数中: localSocket->deleteLater();建议:
b) 在 processArgs 函数中: w->move(pos);
w->show();建议:
a) 版本号管理:
b) 注释优化:
具体修改建议示例: // 定义常量
static const int SOCKET_WRITE_TIMEOUT = 1000;
void SingleApplication::newClientProcess(const QString &key, const QByteArray &message)
{
QLocalSocket *localSocket = new QLocalSocket();
localSocket->connectToServer(userServerName(key));
if (localSocket->waitForConnected(1000)) {
if (localSocket->state() == QLocalSocket::ConnectedState) {
qDebug() << "Connected to existing instance, sending message";
localSocket->write(message);
localSocket->flush();
// 检查写入是否成功
if (!localSocket->waitForBytesWritten(SOCKET_WRITE_TIMEOUT)) {
qWarning() << "Failed to write message:" << localSocket->errorString();
}
}
} else {
qWarning() << "Failed to connect to existing instance:" << localSocket->errorString();
}
// 确保资源正确释放
localSocket->disconnectFromServer();
localSocket->deleteLater();
}void SingleApplication::processArgs(const QStringList &list)
{
// ... 其他代码 ...
// 使用更安全的方式处理窗口显示
w->hide();
w->setJsonData(jsonData);
if (cmdManager.enableBypassWindowManagerHint()) {
w->setWindowFlags(w->windowFlags() | Qt::BypassWindowManagerHint);
}
// 使用单次定时器确保安全的异步处理
QTimer::singleShot(0, [this, w, pos]() {
w->adjustSize();
// 确保窗口位置在屏幕范围内
QRect screenGeometry = QApplication::desktop()->screenGeometry();
pos = QPoint(
qBound(0, pos.x(), screenGeometry.width() - w->width()),
qBound(0, pos.y(), screenGeometry.height() - w->height())
);
w->move(pos);
w->show();
});
}这些修改将提高代码的健壮性、可维护性和安全性。 |
Johnson-zs
approved these changes
Jan 4, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Johnson-zs, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
将 move() 调用移到 show() 之前,避免窗口先显示在错误位置再移动导致的闪烁,
同时确保在 setJsonData() 完成布局计算后再获取窗口尺寸。
Log: 修复窗口位置显示不正确的问题
Bug: https://pms.uniontech.com/bug-view-325485.html