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

David Villalobos Cambronero david.villalobos.c at gmail.com
Fri Aug 6 01:35:47 CEST 2010


Many thanks, great to know.


Regards.
David


On Thu, Aug 5, 2010 at 17:23, Bill King <bill.king at nokia.com> wrote:

> 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
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100805/8c3a6463/attachment.html 


More information about the Qt-interest-old mailing list