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?

Qt Code:
  1. bool MainWindowImpl::createConnection()
  2. {
  3. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
  4. db.setHostName("microsoft.com");
  5. db.setDatabaseName("thedata");
  6. db.setUserName("bill");
  7. db.setPassword("billybob");
  8.  
  9. if (!db.isValid()){
  10. QMessageBox::critical(0,QObject::tr("Database is not valid"),"I can't open the damned thing.");
  11. return false;
  12. }
  13. else{
  14. if (!db.open()) {
  15. QMessageBox::critical(0, QObject::tr("Database Error"),db.lastError().text());
  16. return false;
  17. }
  18. QMessageBox::information(0, QObject::tr("Database Opened Just Fine"),"apparently the username/password was valid");
  19. return true;
  20. }
  21. }
To copy to clipboard, switch view to plain text mode