Results 1 to 13 of 13

Thread: What does QSqlDatabase::removeDatabase do exactly?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2010
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default What does QSqlDatabase::removeDatabase do exactly?

    I was testing the sqlbrowser example provided in the QTDIR/demos/sqlbrowser directory but somehow ran into a "segmantation fault"

    Here is what I did:
    1. try to connect to a bogus database by purposely providing a wrong database name,
    and it return "An error occurred while opening the connection: Unknown database 'bogus' QMYSQL: Unable to connect" as expected.
    2. Now, try to connect to the correct database, and I got "segmantation fault"!!

    The key here is "when" this unable to connect happens... I mean if I created a successful connection on the very first try, then any subsequent attempts to make a correct/incorrect connection will just work as they are supposed to without causing any segmentation fault. However, if the very first attempt failed like when I provided a wrong database name, then the subsequent attempt to make another connection will cause the segmentation fault.

    here is the code that's causing the headache..

    Qt Code:
    1. QSqlError Browser::addConnection(const QString &driver, const QString &dbName, const QString &host,
    2. const QString &user, const QString &passwd, int port)
    3. {
    4. static int cCount = 0;
    5.  
    6. QSqlError err;
    7. QSqlDatabase db = QSqlDatabase::addDatabase(driver, QString("Browser%1").arg(++cCount));
    8. db.setDatabaseName(dbName);
    9. db.setHostName(host);
    10. db.setPort(port);
    11. if (!db.open(user, passwd)) {
    12. err = db.lastError();
    13. db = QSqlDatabase();
    14. QSqlDatabase::removeDatabase(QString("Browser%1").arg(cCount));
    15. }
    16. connectionWidget->refresh();
    17.  
    18. return err;
    19. }
    To copy to clipboard, switch view to plain text mode 

    What I found is that if I commented out "QSqlDatabase::removeDatabase(QString("Browser%1") .arg(cCount));", then the segmentation fault goes away...but QSqlDatabase::connectionNames() will return both good and bad connections.....not very useful...

    I also found that this seems to be happening to the Solaris platform only. As I have the same version of Qt and MySQL loaded on another Windows machine, and this segmentation faults never happened to that Windows version of sqlbrowser demo.

    so the question is what does QSqlDatabase::removeDatabase ( const QString & connectionName ) do exactly other than remove the database connection connectionName from the list of database connections ?

    I'm using
    Qt 4.5.3
    MySQL 5.1.44

    any feedback is appreciated....
    Last edited by wysota; 19th March 2010 at 09:04.

Similar Threads

  1. QSQLDatabase
    By hoshy in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2009, 15:09
  2. Passing around a QSqlDatabase
    By darkadept in forum Qt Programming
    Replies: 2
    Last Post: 8th September 2007, 08:41
  3. QSqlDatabase
    By Pragya in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2007, 17:53
  4. QSqlDatabase
    By raphaelf in forum Qt Programming
    Replies: 10
    Last Post: 10th May 2006, 15:15
  5. Replies: 10
    Last Post: 6th March 2006, 16:08

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.