Frozenjim
12th October 2008, 20:38
My little test app connects just fine to a valid database.
If I change the variables so that I am connecting to "microsoft.com" (for example), I get the expected error message.
If I connect to a valid host with invalid credentials, I get the expected error.
But when I connect to some mySQL databases, my app just freezes while waiting for the connection. No message is ever returned because the app just freezes entirely - forever.
Is there any way to timeout the db.open() or db.isvalid()? Or is there some way to use processevents() to decide that it's time to terminate the attempt?
bool MainWindowImpl::createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("microsoft.com");
db.setDatabaseName("thedata");
db.setUserName("bill");
db.setPassword("billybob");
if (!db.isValid()){
QMessageBox::critical(0,QObject::tr("Database is not valid"),"I can't open the damned thing.");
return false;
}
else{
if (!db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"),db.lastError().text());
return false;
}
QMessageBox::information(0, QObject::tr("Database Opened Just Fine"),"apparently the username/password was valid");
return true;
}
}
If I change the variables so that I am connecting to "microsoft.com" (for example), I get the expected error message.
If I connect to a valid host with invalid credentials, I get the expected error.
But when I connect to some mySQL databases, my app just freezes while waiting for the connection. No message is ever returned because the app just freezes entirely - forever.
Is there any way to timeout the db.open() or db.isvalid()? Or is there some way to use processevents() to decide that it's time to terminate the attempt?
bool MainWindowImpl::createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("microsoft.com");
db.setDatabaseName("thedata");
db.setUserName("bill");
db.setPassword("billybob");
if (!db.isValid()){
QMessageBox::critical(0,QObject::tr("Database is not valid"),"I can't open the damned thing.");
return false;
}
else{
if (!db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"),db.lastError().text());
return false;
}
QMessageBox::information(0, QObject::tr("Database Opened Just Fine"),"apparently the username/password was valid");
return true;
}
}