ayanda83
14th November 2013, 20:30
hi everyone, I have struggled for a long time with trying to connect my progam to a PostgreSQL database. At first I tried connecting my program to a mysql database but after a long time of trying to building the mysql driver i gave up and tried a different database (i.e. Postgresql) and still can't connect even with postgresql. code below.
Server_A::Server_A(QObject *parent) :
QObject(parent)
{
server = new QTcpServer(this);
// threadPool.setMaxThreadCount(5000);
QString connectionStr = "Driver={PostgreSQL};Server=127.0.0.1;Port=5432;Dat abase=AsicamtheDB;Uid=root;Pwd=ayaman;";
db = QSqlDatabase::addDatabase("QODBC");
db.setConnectOptions();
db.setDatabaseName(connectionStr);
if(db.open())
{
qDebug() << "connected to database" <<endl;
}
else
{
qDebug() << "Not connected" <<endl;
qDebug() << db.lastError() <<endl;
qDebug() << db.drivers() <<endl;
}
Server_A::Server_A(QObject *parent) :
QObject(parent)
{
server = new QTcpServer(this);
// threadPool.setMaxThreadCount(5000);
QString connectionStr = "Driver={PostgreSQL};Server=127.0.0.1;Port=5432;Dat abase=AsicamtheDB;Uid=root;Pwd=ayaman;";
db = QSqlDatabase::addDatabase("QODBC");
db.setConnectOptions();
db.setDatabaseName(connectionStr);
if(db.open())
{
qDebug() << "connected to database" <<endl;
}
else
{
qDebug() << "Not connected" <<endl;
qDebug() << db.lastError() <<endl;
qDebug() << db.drivers() <<endl;
}