oopapidocs
2.0
|
00001 #include "dbconnectionsettings.h" 00002 #include <QSettings> 00003 #include <QMessageBox> 00004 00005 void DbConnectionSettings::save(QSqlDatabase db) { 00006 QSettings s; 00007 s.setValue("dbname", db.databaseName()); 00008 s.setValue("dbhost", db.hostName()); 00009 s.setValue("dbuser", db.userName()); 00010 s.setValue("dbpw", db.password()); 00011 s.setValue("dbtype", db.driverName()); 00012 00013 } 00014 00015 QSqlDatabase DbConnectionSettings::lastSaved(QString connectionName) { 00016 QSqlDatabase db; 00017 if (!QSqlDatabase::contains(connectionName)) { 00018 QSettings s; 00019 QString dbname = s.value("dbname").toString(); 00020 QString dbhost = s.value("dbhost").toString(); 00021 QString dbuser = s.value("dbuser").toString(); 00022 QString dbpw = s.value("dbpw").toString(); 00023 QString dbtype = s.value("dbtype").toString(); 00024 db = QSqlDatabase::addDatabase(dbtype, connectionName); 00025 db.setDatabaseName(dbname); 00026 db.setHostName(dbhost); 00027 db.setUserName(dbuser); 00028 db.setPassword(dbpw); 00029 00030 } 00031 else { 00032 db = QSqlDatabase::database(connectionName); 00033 00034 } 00035 return db; 00036 } 00037