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).
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.
来源:https://stackoverflow.com/questions/33014413/qsqldatabase-open-always-returns-true-after-update