PDA

View Full Version : QtSQL and databse



prophet0
17th December 2011, 21:07
how can i use a settings class to use DB for my entire application




db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("MYDATABASE");
db.setUserName("root");
db.setPassword("MYPASS");

i need to use if(db.open) across my application how would i be able to access it

could you please use examples thanks!!

Lykurg
17th December 2011, 21:31
Hi,

see the second parameter of QSqlDatabase::addDatabase() and use it in conjunction with QSqlDatabase::database() to access the database from everywhere in your application.

Only open the database at start and it will stay open (normally). Or make a global function which always checks if it is open if a local test is to much coding for you.

prophet0
18th December 2011, 06:22
thats perfect thanks :)