I configued Qt for Mysql using following instructons
Creating the MySQL client library
The client libraries (libmysql.dll and libmysql.lib) that are shipped with MySQL are compiled with the Microsoft compiler and cannot be linked using the MinGW compiler. Therefore, we first need to create a MinGW compatible library out of libmysql.dll.
This can be done from the command line as follows:
# cd c:\mysql\lib\opt
# reimp -d libmysql.lib
# dlltool -k --input-def libmysql.def --dllname libmysql.dll --output-lib libmysql.a
reimp is a tool to convert Microsoft's new-style (short) import libraries to be compatible with the Win32 ports of the GNU tools (MinGW, Cygwin). It reads the MS import library and writes all the library imports to a corresponding libmysql.def file used by dlltool to create the import library.
dlltool takes the libmysql.def file that was created by reimp, and creates the GNU compatible library libmysql.a.
Both these tools are found in mingw-utils.
Building the QMYSQL plugin dll
Build the Qt MySQL plugin based on the above MinGW compatible library using the following steps. This assumes that QT has been installed at C:\qt. Substitute the path that you have selected into the following commands. You need the MySQL C Include Files/Lib Files package for this step.
# cd c:\qt\src\plugins\sqldrivers\mysql
# qmake -o Makefile "INCLUDEPATH+=C:\MYSQL\INCLUDE" "LIBS+=-LC:\MYSQL\LIB\OPT -lmysql" mysql.pro
# mingw32-make
The files qsqlmysql.dll, qsqlmysqld.dll, libqsqlmysql.a, libqsqlmysqld.a will appear in your c:\qt\plugins\sqldrivers directory.
Make sure that libmysql.dll is in your path. This is located in the C:\mysql\bin directory which can be placed in the path environment variable and is provided by the MySQL client libraries (it is also included in the Include Files/Lib Files package in the full version of MySQL5).
I can see a libmysql.a and LIBMYSQL.def file created in C:\mysql\lib\opt\
then I copied libmySQL.dll from c:\mysql\bin to D:\Qt\4.4.3\bin and also copied this dll where my executable resides.
No when I query to fetch list of database drives I can see
QSQLITE
QMYSQL3
QMYSQL
QODBC3
QODBC
also I m able to connect to Mysql database on remot server
But the problem is that I m not able to fetch any records from the DB..
I use follwing code
db.setHostName("192.168.8.193");
db.setDatabaseName("gaur01");
db.setUserName("gaur");
db.setPassword("gaur123");
db.setPort(3306);
if (!db.open()) {
out <<"Error\n";
out << db.lastError().driverText();
out << "\n";
out << db.lastError().databaseText();
}
else
{
out <<"DB open successfully";
if(query.
lastError().
type() != QSqlError::NoError) {
out << "\nError Occured 1 : " << query.lastError().text();
}
query.prepare("SELECT * FROM temp");
query.exec();
if(query.
lastError().
type() != QSqlError::NoError) {
out << "\nError Occured 2 : " << query.lastError().text();
}
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.8.193");
db.setDatabaseName("gaur01");
db.setUserName("gaur");
db.setPassword("gaur123");
db.setPort(3306);
if (!db.open()) {
out <<"Error\n";
out << db.lastError().driverText();
out << "\n";
out << db.lastError().databaseText();
}
else
{
out <<"DB open successfully";
if(query.lastError().type() != QSqlError::NoError)
{
out << "\nError Occured 1 : " << query.lastError().text();
}
query.prepare("SELECT * FROM temp");
query.exec();
if(query.lastError().type() != QSqlError::NoError)
{
out << "\nError Occured 2 : " << query.lastError().text();
}
To copy to clipboard, switch view to plain text mode
its output is
DB open successfully
Error Occured 1 : Driver not loaded Driver not loaded
Error Occured 2 : Driver not loaded Driver not loaded
DB open successfully
Error Occured 1 : Driver not loaded Driver not loaded
Error Occured 2 : Driver not loaded Driver not loaded
To copy to clipboard, switch view to plain text mode
any help ????
Bookmarks