Passing around a QSqlDatabase
This is something I stumbled upon when compiling my Qt4 code on a windows box. I'm using Qt 4.3.1.
Originally I had a dynamically loaded plugin (using QPluginLoader) that had a method with this syntax:
On Linux everything compiled and ran fine but when I moved my code over to the Windows box it compiled fine but gave me a: The file "c:/my/project/plugin.dll" is not a valid Qt plugin. error message.
It took me a while to connect this message to the actual problem so I hope this helps someone else out if they are banging their heads against a wall.
I realize that I shouldn't return a QSqlDatabase object but instead use the QSqlDatabase::addDatabase(...) and QSqlDatabase::database() static methods with a named database.
One question I have is, is this the only Qt4 class that I shouldn't use as a return object or are there others?
Re: Passing around a QSqlDatabase
Ok i've delved further into this and have discovered that if I call QSqlDatabase::addDatabase from a dynamically loaded plugin the plugin will not load on windows. It loads fine under linux.
Now I'm beginning to wonder if this is a bug or a limitation of Qt4 on windows?
I think I'm going to have to rework things so that I'm not adding a database from a plugin.
Re: Passing around a QSqlDatabase
Did you link the main application against the sql library? As far as I remember all Qt plugins are initialized in QApplication constructor, not when addDatabase is called... What does QSqlDatabase::drivers return?