Results 1 to 11 of 11

Thread: QSqlDatabasePrivate::removeDatabase: connection 'menu_settings' is still in use, all

  1. #1
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QSqlDatabasePrivate::removeDatabase: connection 'menu_settings' is still in use, all

    When I close my application I get the following message

    QSqlDatabasePrivate::removeDatabase: connection 'menu_settings' is still in use, all queries will cease to work.

    Not sure what this is. I have tried closing all the databases I make, and I have tried clearing all of the queries I have made and nothing seems to get rid of this message. The only thing that I know does work is if I don't use the database in a plugin, I don't get this message.

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabasePrivate::removeDatabase: connection 'menu_settings' is still in use, all

    Maybe that plugin uses one of the QSql*Model classes?

  3. #3
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabasePrivate::removeDatabase: connection 'menu_settings' is still in use,

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabasePrivate::removeDatabase: connection 'menu_settings' is still in use, all

    How do you create that "menu_settings" connection?

  5. #5
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabasePrivate::removeDatabase: connection 'menu_settings' is still in use,

    in the plugin's constructor. I call:

    QSqlDatabase db = QSqlDatabase::addDatabase ("QSQLITE", "menu_settings");

    Is there another way to do this?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabasePrivate::removeDatabase: connection 'menu_settings' is still in use,

    Quote Originally Posted by rianquinn
    in the plugin's constructor. I call:

    QSqlDatabase db = QSqlDatabase::addDatabase ("QSQLITE", "menu_settings");
    Does this error occur if you add similar statement in the application?

    Quote Originally Posted by rianquinn
    Is there another way to do this?
    Probably not.

  7. #7
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabasePrivate::removeDatabase: connection 'menu_settings' is still in use,

    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabasePrivate::removeDatabase: connection 'menu_settings' is still in use, all

    Do you destroy the objects retrieved from plugins when your application closes?

  9. #9
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabasePrivate::removeDatabase: connection 'menu_settings' is still in use,

    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

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabasePrivate::removeDatabase: connection 'menu_settings' is still in use,

    Quote Originally Posted by rianquinn
    The weird thing is, if when the plugin is unloaded, I call QSqlDatabase::removeDatabase, I still get the error.
    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).

    Did you check Trolltech task tracker? This might be also some bug.

  11. #11
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabasePrivate::removeDatabase: connection 'menu_settings' is still in use,

    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!


  12. The following user says thank you to rianquinn for this useful post:

    emctoo (15th March 2011)

Similar Threads

  1. cannot share the database connection!!!!
    By cbarmpar in forum Qt Programming
    Replies: 13
    Last Post: 23rd September 2008, 15:42
  2. SQL connection closure problem.
    By cbarmpar in forum Qt Programming
    Replies: 1
    Last Post: 8th September 2008, 09:42
  3. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 11:22
  4. Replies: 3
    Last Post: 2nd August 2007, 22:28
  5. How do I keep the client connection open ?
    By probine in forum Newbie
    Replies: 2
    Last Post: 25th March 2006, 20:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.