The funny thing is you don't have to store the connection anywhere because Qt will automatically pick up the default connection. The name lookup is hash-based so it yields almost no overhead (apart from using a mutex to lock the dictionary).
You have to pass *db everywhere which is awkward. And you have to delete the instance of the object somewhere.I stored it as a class member in my database abstraction class. Works perfectly. Where is there going to be a problem?
Besides, there is a rule of a thumb that implicitly shared classes are to be created on the stack. There is nothing wrong in keeping a pointer to a database - if you want to do it and you have a reason, do it, but please don't teach others to follow Passing pointers around is not a good C++ habit.






Reply With Quote
Bookmarks