QSqlDatabase open always returns true after update

五迷三道 提交于 2019-12-02 10:22:13

问题


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).


回答1:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!