I have a local Database running on localhost:3306, which I access with MySQL Workbench. This works fine, I can create alter, do whatever I want to table. I have two Schemas, “test” and “test2”.
I want to connect to it via Qt. here is my code:
QSqlDatabase m_db = QSqlDatabase::addDatabase("QPSQL");
m_db.setHostName("localhost");
m_db.setDatabaseName("test");
m_db.setPort(3306);
m_db.setUserName("root");
m_db.setPassword("MyAwesomePasswordThatIsUnHackableAndNotMyBirthdayAtAll...");
bool ok = m_db.open();
I followed the example found here QSqlDataBase Class reference
and m_db.open() always returns false. I’m not too sure what I have to pass to addDataBase() or setDataBaseName. Thanks for the help!
Edit: If I use addDatabase(“QMYSQL”) the error is “Driver not loaded”
I’m on windows 7, using Qt 4.8.1.
There is no MySQL precompiled plugin installed. You have to compile it yourself. Or you may also use ODBC gateway to your MySQL database, since QODBC plugin is installed or can be easily compiled (without a need of MySQL development libraries).