PDA

View Full Version : MyLibrary loading mysql driver related problem



kornicameister
19th August 2011, 11:16
I have written my own library to separate strictly database job from main application code, library will be pretty vital for whole application to work, but I encountered a little problem which beyond obvious solution I can not solve.

The problem lies is loading the driver for mysql. Driver not loads, as QCoreApplication must be initialized before I could even have tried to load any driver. Well ok, but I dragged to my library whole class which wraps connection data, opens the database and than safely closes it.

Is there any other solution, apart from loading the driver back in main application, where QCoreApplication is initialized ?

I moved loading the driver back to my application code, than I tried
- to pass to library connection name -> with no success, db is not opening
- to pass to library whole QSqlDatabase object, or pointer, or reference, db is opening, but every next method in library which requires access to db returns that db is closed

I am starting to think that only option left here is to move whole connection establishment job back to my application code, but I am thinking... is this not thread problem. I mean application is another thread and library is another, so perhaps driver loaded in one thread can not be reused in another ?

high_flyer
22nd August 2011, 10:05
I don't see where the problem is.
Just don't make the connection to the database when you load your lib, rather, make a call from your application to the lib, to connect to the database.
This will have to be after QCoreApplication has been initialized.