Well, I have following chunk of code:
{
// sets up database paramaters
m_Database.setHostName(db_host);
m_Database.setUserName(db_username);
m_Database.setPassword(db_password);
m_Database.setDatabaseName(db_name);
// tries to connect to database
m_bConnectionEstablished=m_Database.open();
if(!m_bConnectionEstablished)
{
//qFatal("Failed to connect to database. Aborting.");
/*
int ret=QMessageBox::critical(0,
tr("Critical Error"),
tr("Failed to connect to database. Aborting."));
*/
QString errorString
(m_Database.
lastError().
databaseText());
errorString.append(": ");
errorString.append(m_Database.lastError().driverText());
tr("Critical Error"),
errorString);
qApp->quit(); // terminates application, does not work?!
}
{
// 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);
m_Database.setDatabaseName(db_name);
// tries to connect to database
m_bConnectionEstablished=m_Database.open();
if(!m_bConnectionEstablished)
{
//qFatal("Failed to connect to database. Aborting.");
/*
int ret=QMessageBox::critical(0,
tr("Critical Error"),
tr("Failed to connect to database. Aborting."));
*/
QString errorString(m_Database.lastError().databaseText());
errorString.append(": ");
errorString.append(m_Database.lastError().driverText());
int ret=QMessageBox::critical(0,
tr("Critical Error"),
errorString);
qApp->quit(); // terminates application, does not work?!
}
To copy to clipboard, switch view to plain text mode
What I want to achieve, if database connection fails, application must terminate immediately. qApp->quit() does not work, are there any other ideas?
Bookmarks