Thanks Wysota. I placed the DLL library in my application directory and it works now.
The code from my first post works and gives me the following result:
("QMYSQL3", "QMYSQL", "QODBC3", "QODBC", "QSQLITE")
Press any key to continue . . .
However when I add a few more lines to my code to open a test database it doesn't work. Here is the new code:
-----
#include <QCoreApplication>
#include <QSqlDatabase>
#include <QStringList>
#include <QtDebug>
#include <QPushButton>
#include <QApplication>
#include <QSqlError>
#include <QSqlQuery>
#include <iostream>
using namespace std;
int main( int argc, char **argv )
{
mydb->addDatabase("QMYSQL");
mydb->setHostName("w.x.y.z"); //number changed
mydb->setPort(zzzz); //number changed
mydb->setDatabaseName("test");
mydb->setUserName("tmp");
mydb->setPassword("tmp123");
bool ok = mydb->open();
qDebug()<<mydb->lastError();
cout<<"ok="<<ok<<endl;
}
#include <QCoreApplication>
#include <QSqlDatabase>
#include <QStringList>
#include <QtDebug>
#include <QPushButton>
#include <QApplication>
#include <QSqlError>
#include <QSqlQuery>
#include <iostream>
using namespace std;
int main( int argc, char **argv )
{
QCoreApplication app( argc, argv );
qDebug() << QSqlDatabase::drivers();
QSqlDatabase *mydb = new QSqlDatabase();
mydb->addDatabase("QMYSQL");
mydb->setHostName("w.x.y.z"); //number changed
mydb->setPort(zzzz); //number changed
mydb->setDatabaseName("test");
mydb->setUserName("tmp");
mydb->setPassword("tmp123");
bool ok = mydb->open();
qDebug()<<mydb->lastError();
cout<<"ok="<<ok<<endl;
}
To copy to clipboard, switch view to plain text mode
------
And here's the output of the above code:
("QMYSQL3", "QMYSQL", "QODBC3", "QODBC", "QSQLITE")
QSqlError(-1, "Driver not loaded", "Driver not loaded")
ok=0
Press any key to continue . . .
Can you please guide me on resolving the issue here? What am I doing wrong here?
Thanks,
Ashish
Bookmarks