Ok, here is the whole constructor of my CDatabaseFoundation class:
CDatabaseFoundation
::CDatabaseFoundation(QString db_type,
QString db_host,
{
// sets up database paramaters
m_Database.setHostName(db_host);
m_Database.setUserName(db_username);
m_Database.setPassword(db_password);
// tries to connect to database
m_bConnectionEstablished=m_Database.open();
if(!m_bConnectionEstablished)
qFatal("Failed to connect to database. Aborting.");
//create database + tables if they don't exists yet
//CreateDatabaseAndTables();
//call seletedDatabase statement here because you're sure the the database exists
m_Database.setDatabaseName(db_name);
/*
m_pModel=new QSqlRelationalTableModel(this);
Q_CHECK_PTR(m_pModel);
//all changes will be cached in the model until either submitAll() or revertAll() is called
m_pModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
*/
//addRelations(m_pModel);
}
CDatabaseFoundation::CDatabaseFoundation(QString db_type, QString db_host,
QString db_name, QString db_username,
QString db_password): QObject()
{
// sets up database paramaters
m_Database=QSqlDatabase::addDatabase(db_type);
m_Database.setHostName(db_host);
m_Database.setUserName(db_username);
m_Database.setPassword(db_password);
// tries to connect to database
m_bConnectionEstablished=m_Database.open();
if(!m_bConnectionEstablished)
qFatal("Failed to connect to database. Aborting.");
//create database + tables if they don't exists yet
//CreateDatabaseAndTables();
//call seletedDatabase statement here because you're sure the the database exists
m_Database.setDatabaseName(db_name);
/*
m_pModel=new QSqlRelationalTableModel(this);
Q_CHECK_PTR(m_pModel);
//all changes will be cached in the model until either submitAll() or revertAll() is called
m_pModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
*/
//addRelations(m_pModel);
}
To copy to clipboard, switch view to plain text mode
Bookmarks