class DataBaseManager : public QObject
{
Q_OBJECT
public:
explicit DataBaseManager(QObject *parent = nullptr);
~DataBaseManager();
bool OpenDB_Teacher(const QString &dataName);
bool OpenDB_Student(const QString &dataName);
// 单实例运行
static DataBaseManager *Instance()
{
static QMutex mutex;
if (NULL == m_DB_Manager) {
QMutexLocker locker(&mutex);
if (!m_DB_Manager) {
m_DB_Manager = new DataBaseManager();
}
}
return m_DB_Manager;
}
signals:
public slots:
private:
// 数据库管理
static DataBaseManager *m_DB_Manager;
// 数据库
QSqlDatabase m_DB_Teacher;//老师
QSqlDatabase m_DB_Student;//学生
};
#include <QDebug>
#include <QSqlError>
DataBaseManager *DataBaseManager::m_DB_Manager = NULL;
DataBaseManager::DataBaseManager(QObject *parent) : QO