Hi Guys,
I am working on a small command line application in which I need basic MySQL connectivity. I am using Qt Creator 2.4.1 with Qt 4.7.4 on Windows 7. I created a "Qt Console Application" project and tried to compile the following trivial program.
#include <QtCore/QCoreApplication>
#include <QtSql/QSqlDatabase>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
myDb.setHostName( "localhost" );
myDb.setUserName( "root" );
myDb.setPassword( "*********" );
myDb.setDatabaseName( "mytestdb" );
bool success = myDb.open();
if ( success ) cout << "Database connection established successfully" << endl;
else cout << "Database connection failed" << endl;
myDb.close();
QSqlDatabase::removeDatabase( myDb.
database().
connectionName() );
return a.exec();
}
#include <QtCore/QCoreApplication>
#include <QtSql/QSqlDatabase>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase myDb = QSqlDatabase::addDatabase( "QMYSQL" );
myDb.setHostName( "localhost" );
myDb.setUserName( "root" );
myDb.setPassword( "*********" );
myDb.setDatabaseName( "mytestdb" );
bool success = myDb.open();
if ( success ) cout << "Database connection established successfully" << endl;
else cout << "Database connection failed" << endl;
myDb.close();
QSqlDatabase::removeDatabase( myDb.database().connectionName() );
return a.exec();
}
To copy to clipboard, switch view to plain text mode
On building this project, I get following, about 18 errors.
Please tell me what am I doing wrong and where?
Thanks!!!
Bookmarks