[Qt-interest] Using a single MySQL Connection in the whole project

Bill King bill.king at nokia.com
Fri Aug 6 01:23:24 CEST 2010


Yes, this is the preferred method of doing it ;)

On 08/05/2010 03:14 AM, ext Luis Lezcano Airaldi wrote:
> There's already a Singleton implementation for the database connections.
> When you create the database conenction (I do it in main() ) you do:
>
> QSqlDtabase db = QSqlDatabase::addDatabase("QMYSQL", "db_name");
>
> I don't know if this is the right way, but this is how I do it:
>
> //class definition
>    class SomeClass {
>       private:
>           QSqlDatabase db;
>    }
>
> //class implementation (it can be the constructor or another method)
>       db = QSqlDatabase::database("db_name");
>
> Saludos!
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>    


-- 
Bill King, Software Engineer
Qt Development Frameworks, Nokia Pty Ltd
Brisbane Office




More information about the Qt-interest-old mailing list