#ifndef MYGLOBAL_H#define MYGLOBAL_H#include <QtGui>#include <QtSql>class MyGlobal {public: QString DbHost; QString DbName; QString DbUser; QString DbPass; QSqlDatabase DataBase; MyGlobal(); bool OpenDB();};#endif // MYGLOBAL_H
#include "myglobal.h"MyGlobal Global;MyGlobal::MyGlobal(){}bool MyGlobal::OpenDB(){ DataBase = QSqlDatabase::addDatabase("QPSQL","First"); DataBase.setHostName(DbHost); DataBase.setDatabaseName(DbName); DataBase.setUserName(DbUser); DataBase.setPassword(DbPass); if (DataBase.open()) return true; return false;}
Global.DbHost = "192.168.1.123";Global.DbName = "mybase";Global.DbUser = "im_super";Global.DbPass = "secret";if (!Global.OpenDB()) { qDebug() << "Shit happyness!";}...