modbus_rtu_test/mdbguard.h

74 lines
1.3 KiB
C++

#ifndef MDBGUARD_H
#define MDBGUARD_H
#include <QMutex> //线程保护序列化
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QtSql/QSqlError>
#include <QtSql/QSqlIndex>
#include <QtSql/QSqlRecord>
#include <QTextStream>
#include <QStringList>
#include <QVariant>
#include <windows.h>
#include <QFile>
#include <QFileDialog>
typedef struct
{
QString a;
DWORD b;
long c;
}CDBPARAMETER;
typedef std::vector<CDBPARAMETER*> ParamListVec;
class MyDataBase
{
public:
MyDataBase();
~MyDataBase();
private:
MyDataBase(const MyDataBase &);
MyDataBase operator =(const MyDataBase &);
private:
static MyDataBase *m_pInstance;
public:
static MyDataBase * GetInstance();
bool ConnectAccessDB(const QString &strDBName,const QString &strUser,const QString &strPwd) const;
public:
QSqlDatabase GetDatabase() const
{
return QSqlDatabase::database("MyAccessDB");
}
QSqlQuery GetSqlQuery() const
{
static QSqlQuery query(m_pInstance->GetDatabase());
return query;
}
bool IsValid() const
{
return this->GetDatabase().isValid();
}
bool IsConnected() const
{
return this->GetDatabase().isOpen();
}
};
class MdbGuard
{
public:
MdbGuard();
};
#endif // MDBGUARD_H