1

After updating Qt from 5.5 to 5.6 QSqlDatabase:open always returns true - even if the host is not reachable and/or username/password/database settings are set to nonsense.

Test code:

QSqlDatabase* db = new QSqlDatabase(QSqlDatabase::addDatabase("QMYSQL", "TESTCONNECTION"));
db->setHostName(ip);
db->setPort(port);
db->setUserName(user);
db->setPassword(pwd);
db->setDatabaseName(dbName);
db->setConnectOptions("MYSQL_OPT_CONNECT_TIMEOUT=4");
bool ok = db->open();

I compiled the Qt sql libs against the latest mysql version (5.6.x).

demonplus
  • 5,613
  • 12
  • 49
  • 68
OnWhenReady
  • 939
  • 6
  • 15

1 Answers1

4

This was actually a reported bug: QSqlDatabase::open always returns true with QMYSQL. The page shows that it was solved at 15/Sep/15 7:03 AM and implemented in version 5.5.1, but this however is before the 5.6 alpha release, which was on 8/Sep/15, so that explains why it is not yet fixed in your version.

agold
  • 6,140
  • 9
  • 38
  • 54
  • Thank you very much. This was/is annoying as ****. Tried it on 5.5.0 and 5.6 with three different versions of mysql (5.1, 5.5, 5.6) and still got the same behaviour. I really don't know why i did not find the bug report. Cheers. – OnWhenReady Oct 08 '15 at 13:33
  • onwhenready - Can you please add details as how did applying patch solve the problem and steps for applying patch? Having exact same problem in my application. TIA – user3393753 Oct 19 '15 at 19:35