修复程序退出问题

master
Mike Solar 2023-08-13 17:00:01 +08:00
parent 63c012709e
commit 979595c8d8
1 changed files with 2 additions and 33 deletions

View File

@ -3,37 +3,12 @@
#include <QObject>
#include <QList>
#include "sqlitehelper.h"
template <typename T>
class AutoDeleteList
{
public:
// 添加对象
void add(T *obj)
{
objs.append(obj);
}
// 析构对象列表
~AutoDeleteList()
{
qDeleteAll(objs);
}
private:
QList<T *> objs;
};
class ExitManager : public QObject
{
Q_OBJECT
public:
// 添加需要在退出时自动析构的对象
template <typename T>
void add(T *obj)
{
autoDeleteList.add(obj);
}
// 退出应用程序
void exit(int exitCode = 0)
@ -42,14 +17,8 @@ public:
sqlite_helper.db.close();
QSqlDatabase::removeDatabase("mydb");
// 发射退出应用程序信号
emit exitApplication(exitCode);
::exit(exitCode);
}
signals:
// 退出应用程序信号
void exitApplication(int exitCode);
private:
// 自动析构对象列表
AutoDeleteList<QObject> autoDeleteList;
};