Skip to content

Commit 125922d

Browse files
committed
test shutdown release socket again
1 parent a3f5f15 commit 125922d

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ CMakeLists.txt.user*
4747
.vs
4848
.vscode
4949
*.code-workspace
50+
*.zip

main.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,12 @@ int main(int argc, char *argv[])
8585
translator.load(":/ts/DrCOM_zh_CN.qm");
8686
a.installTranslator(&translator);
8787

88-
MainWindow w;
88+
MainWindow w(&a);
8989
QObject::connect(&a, &SingleApplication::instanceStarted, [&w]() {
9090
qDebug() << "One instance had started. Its window will be shown by the next line of the source code.";
9191
w.ShowLoginWindow();
9292
});
9393

94-
// 关机时接收退出信号,释放socket
95-
QObject::connect(&a, &SingleApplication::aboutToQuit, &w, &MainWindow::QuitDrcom);
96-
9794
QSettings s(SETTINGS_FILE_NAME);
9895
bool bHideWindow=s.value(ID_HIDE_WINDOW, false).toBool();
9996
// 如果是软件自行重启的就不显示窗口

mainwindow.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
#include <QCloseEvent>
1717
#include <QProcess>
1818

19-
MainWindow::MainWindow(QWidget *parent) :
20-
QDialog(parent),
21-
ui(new Ui::MainWindow)
19+
MainWindow::MainWindow(SingleApplication *parentApp, QWidget *parent) :
20+
QDialog(parent),
21+
ui(new Ui::MainWindow),
22+
app(parentApp)
2223
{
24+
// 关机时接收退出信号,释放socket
25+
QObject::connect(app, &SingleApplication::aboutToQuit, this, &MainWindow::QuitDrcom);
26+
2327
qDebug()<<"MainWindow constructor";
2428
ui->setupUi(this);
2529

mainwindow.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <QRegExpValidator>
77
#include <dogcomcontroller.h>
88
#include <QSystemTrayIcon>
9+
#include "singleapplication.h"
910

1011
namespace Ui {
1112
class MainWindow;
@@ -16,7 +17,7 @@ class MainWindow : public QDialog
1617
Q_OBJECT
1718

1819
public:
19-
explicit MainWindow(QWidget *parent = nullptr);
20+
explicit MainWindow(SingleApplication *parentApp=nullptr, QWidget *parent = nullptr);
2021
~MainWindow() override;
2122

2223
void closeEvent(QCloseEvent *) override;
@@ -44,6 +45,7 @@ public slots:
4445

4546
private:
4647
Ui::MainWindow *ui;
48+
SingleApplication *app=nullptr;
4749
const QString CUSTOM_MAC = tr("custom (format: 1A:2B:3C:4D:5E:6F case insensitive)");
4850
const QString APP_NAME = tr("DrCOM JLU Qt version");
4951

0 commit comments

Comments
 (0)