abdol
4th July 2011, 02:44
Hi everyone :),
I want to make a database query...
when I implement a class like:
class IntrfcDB
{
public:
IntrfcDB();
~IntrfcDB();
QSqlDatabase db;
QSqlQueryModel qry;
void useDBConn();
}
void IntrfcDB::useDBConn()
{
qry.exe("select * ...");
}
I get the message: database is not open.
If I rewrite my code like
class IntrfcDB
{
public:
IntrfcDB();
~IntrfcDB();
QSqlDatabase db;
void useDBConn();
}
void IntrfcDB::useDBConn()
{
QSqlQueryModel qry;
qry.exe("select * ...");
}
everything works perfectly (I initialize the connection in the constructor which uses the default connection).
I am new to both c++ and qt. I know that QSqlDatabase is a static function.
I would like to know is it possible to do such thing using the first method? and how?
If not, is this because of static function QSqlDatabase::addDatabase?
Is there anyone to give some explanation :confused: Thank you all :)
I want to make a database query...
when I implement a class like:
class IntrfcDB
{
public:
IntrfcDB();
~IntrfcDB();
QSqlDatabase db;
QSqlQueryModel qry;
void useDBConn();
}
void IntrfcDB::useDBConn()
{
qry.exe("select * ...");
}
I get the message: database is not open.
If I rewrite my code like
class IntrfcDB
{
public:
IntrfcDB();
~IntrfcDB();
QSqlDatabase db;
void useDBConn();
}
void IntrfcDB::useDBConn()
{
QSqlQueryModel qry;
qry.exe("select * ...");
}
everything works perfectly (I initialize the connection in the constructor which uses the default connection).
I am new to both c++ and qt. I know that QSqlDatabase is a static function.
I would like to know is it possible to do such thing using the first method? and how?
If not, is this because of static function QSqlDatabase::addDatabase?
Is there anyone to give some explanation :confused: Thank you all :)