Hello,
I am trying to connect to a local MySQL server, but cannot find out how to select if QSqlDatabase should connect through a socket or port. Qt is version 4.6.3. My simple test code is as follows:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setPort(3306);
db.setDatabaseName("rem");
db.setUserName("test");
db.setPassword("test");
if (!db.open()) {
qDebug() << db.lastError();
}
This gives me:
QSqlError(2002, "QMYSQL: Unable to connect",
"Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")
As you can see it wants to connect using the default socket, which I don't want.
I found db.setConnectOptions("UNIX_SOCKET=blabla")
, with which you can set the socket. Unfortunately I cannot figure out how to unset it.