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..
{
static int cCount = 0;
db.setDatabaseName(dbName);
db.setHostName(host);
db.setPort(port);
if (!db.open(user, passwd)) {
err = db.lastError();
}
connectionWidget->refresh();
return err;
}
QSqlError Browser::addConnection(const QString &driver, const QString &dbName, const QString &host,
const QString &user, const QString &passwd, int port)
{
static int cCount = 0;
QSqlError err;
QSqlDatabase db = QSqlDatabase::addDatabase(driver, QString("Browser%1").arg(++cCount));
db.setDatabaseName(dbName);
db.setHostName(host);
db.setPort(port);
if (!db.open(user, passwd)) {
err = db.lastError();
db = QSqlDatabase();
QSqlDatabase::removeDatabase(QString("Browser%1").arg(cCount));
}
connectionWidget->refresh();
return err;
}
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....
Bookmarks