Results 1 to 8 of 8

Thread: QSqlDatabase error

  1. #1
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default QSqlDatabase error

    I am getting the following error displayed in a console when I close my database program:

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

    I have issued db.close() as part of my destructor but this message persists.

    Any ideas?

    mAx

  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: QSqlDatabase error

    Maybe some instances of QSqlQuery, QSqlQueryModel, QSqlTableModel and similar classes still exist?

  3. #3
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QSqlDatabase error

    I might be missing something because I did have a QSqlTableModel open but I used clear and still receive the error. I have attached my code in hopes that someone can find the error.

    mAx
    Attached Files Attached Files

  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: QSqlDatabase error

    Quote Originally Posted by maxpower View Post
    I did have a QSqlTableModel open but I used clear and still receive the error.
    clear() should be enough, but the problem is that you have many such models and you clear only one of them. You have a memory leak --- each time loadTableView() is invoked, you create a new model and you never delete it.

  5. #5
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QSqlDatabase error

    Okay, I added a "delete model" to each radio button's viewInit logic so that if model already has been initialized it is delete before creating a new one:
    Qt Code:
    1. if( toggled == true )
    2. {
    3. if(viewInit)
    4. {
    5. model->submitAll();
    6. delete model;
    7. }
    8. tableName = "vacation";
    9. loadTableView(tableName);
    10. ui.newPicPB->setEnabled(true);
    11. ui.movePB->setEnabled(true);
    12. }
    To copy to clipboard, switch view to plain text mode 

    However, model-clear() still does not release the only existing model when the program closes as I still receive the error.

    Thanks for the help
    mAx

  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: QSqlDatabase error

    Quote Originally Posted by maxpower View Post
    Okay, I added a "delete model" to each radio button's viewInit logic
    I would add it to loadTableView(), since you invoke it in many places.

    Why do you create a new model in destructor? You won't be able to delete it and you'll get a memory leak. Same thing in closer().

    You have a lot of duplicated code. For example on_matthewRB_toggled(), on_joshuaRB_toggled() and on_vacationsRB_toggled() are exactly the same and you can use just one method instead. Also compare on_settingsPB_clicked() and Init().

  7. #7
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QSqlDatabase error

    Ok, good thinking. Here is my revised code. However, I still get the error even though there should only be one model open at a time. is the ui.tableTV the problem? I really appreciate your help.

    mAx
    Attached Files Attached Files

  8. #8
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QSqlDatabase error

    Well, I finally got it. I moved my model->submitAll() from the destructor to closer() and then replaced the model->clear() there with delete model. I also moved db.close() to closer(). Guess I still don't now why clear() doesn't work, but hey, it works. Thanks for all your help.

    mAx

Similar Threads

  1. Qt-x11-commercial-src-4.2.0-snapshot-20060824 error
    By DevObject in forum Installation and Deployment
    Replies: 4
    Last Post: 24th August 2006, 23:31
  2. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  3. Problems
    By euthymos in forum Installation and Deployment
    Replies: 2
    Last Post: 13th June 2006, 19:11
  4. Fed up with M$ Window$ !!! Why is Tux leaving me alone???
    By fullmetalcoder in forum General Discussion
    Replies: 35
    Last Post: 18th March 2006, 12:57
  5. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54

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.