PDA

View Full Version : What does it mean by "value class" ?



jezz
10th April 2011, 16:24
The Assistant said:
"QSqlDatabase is a value class. Changes made to a database connection via one instance of QSqlDatabase will affect other instances of QSqlDatabase that represent the same connection."

What does it mean by "value class"?
I only have one database connection in my application. Should I use a pointer to it everywhere in the program? Or shouldn't I?



class MyApp1:public QApplication {

public:
QSqlDatabase db() {
return db;
}

private:
QSqlDatabase db;
}


class MyApp2:public QApplication {

public:
QSqlDatabase *db() {
return &db;
}

private:
QSqlDatabase db;
}


Which is better? MyApp1 or MyApp2 ?

Thanks !

Archimedes
10th April 2011, 19:20
http://drdobbs.com/184401955

You don't need to store anything, a simple call to QSqlDatabase::database() is enough in most cases.