the plugin does use QSqlModel classes, but if I comment them out, I still get this bizzar error. I think I am going to try to find out where in the Qt code its coming from.
the plugin does use QSqlModel classes, but if I comment them out, I still get this bizzar error. I think I am going to try to find out where in the Qt code its coming from.
How do you create that "menu_settings" connection?
in the plugin's constructor. I call:
QSqlDatabase db = QSqlDatabase::addDatabase ("QSQLITE", "menu_settings");
Is there another way to do this?
Does this error occur if you add similar statement in the application?Originally Posted by rianquinn
Probably not.Originally Posted by rianquinn
The SQLITE database is being used by each plugin and the main application. This error only occurs when its added in the plugins. Meaning, if I disable all of the plugins, even though I am calling this line of code in the main app, I do not get the error.
Do you destroy the objects retrieved from plugins when your application closes?
no, the QSqlDatabase is being defined by value not by reference. The weird thing is, if when the plugin is unloaded, I call QSqlDatabase::removeDatabase, I still get the error. But if I run QSqlDatabase::removeDatabase in the main app, no error occurs. In fact, no matter where I call QSqlDatabase::removeDatabase in the plugin, I get the error, and the error occurs when this function is called. So I guess, if you don't call this function it is called for you.
Basically, I have figured out that the function call QSqlDatabase::removeDatabase, is what is causing the error, but how do you prevent this error from occuring when you call this function from a plugin
The only thing that comes to my mind is that QApplication instance might be destroyed before the plugin (or rather the object that was created by the plugin).Originally Posted by rianquinn
Did you check Trolltech task tracker? This might be also some bug.
Ok..... here is the solution. When making a plugin, you have to make a class that inherits your Plugin Interface. In the private section of this class, I defined the database that I would be using. Turns out that the main application closes all database connections BEFORE closing plugins. I didn't see this because I put the QSqlDatabase::removeDatabase function in the same function as QSqlDatabase::addDatabase, which Qt doesn't like. Instead, you have to destroy the QSqlDatabase object FIRST, then call QSqlDatabase::removeDatabase. So how does this apply to plugins, well, because I put the definition of the QSqlDatabase::addDatabase at the class scope, this object was getting destroyed AFTER the QSqlDatabase::removeDatabase function was being called, (because this function is called, then the plugins are destroyed.) To fix this problem, you have to destroy the database object, then unload the plugins. The only way I found that this can be done is by leaving the definition of the QSqlDatabase in the functions that they are needed, not at the class level. So instead of this:
class
{
Public
Func ()
Private
QSqlDatabase
}
do this:
class
{
Public
Func ()
}
Func ()
{
QSqlDatabase
}
If more info is needed, just let me know. I hope this helps people in the future!
![]()
emctoo (15th March 2011)
Bookmarks