Hello:
I have legacy code which interfaces with a mysql database using mysql++ mysql connector. ( so using the QT database interfaces is ruled out).
My job is to build QT User Interfaces which talk to the the mysql++ interfaces and then to the database.
So this app has both, QT as well as non-QT classes.
So i wanted to know how to compile , build and run an app that contains QT and non-QT libraries using the qmake system.
SO to experiment, I wrote the following code snippet which is non-QT based.
# include <mysql++.h>
# include <iostream>
int main (void)
{
mysqlpp::Connection conn(false);
bool isOK;
isOK = conn.connect("databasename","localhost","root","root",3306);
std::cout << isOK << std::endl;
int y;
std::cin >> y;
return 0;
}
# include <mysql++.h>
# include <iostream>
int main (void)
{
mysqlpp::Connection conn(false);
bool isOK;
isOK = conn.connect("databasename","localhost","root","root",3306);
std::cout << isOK << std::endl;
int y;
std::cin >> y;
return 0;
}
To copy to clipboard, switch view to plain text mode
The above code returns a 1 upon obtaining a successful connection with the database and 0 if not.
When I compile, link and run the above code using MSVC all is well and I get 1 as an output in the command prompt.
Now on to qmake. I want to know if I can get the same result using qmake.
So I run
qmake -project
qmake -project
To copy to clipboard, switch view to plain text mode
and get an output .pro file named mdb.pro ("mdb" is the name of the project).
I edit the mdb.pro file to contain includepaths and library information. The pro file is as follows:
######################################################################
# Automatically generated by qmake (2.01a) Tue Oct 4 13:35:54 2011
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += . C:\\mcpp\\mysql++\\lib C:\\msqlhome\\include
QMAKE_LIBDIR += . C:\\mcpp\\mysql++\\vc2008\\Debug C:\\msqlhome\\lib
LIBS += libmysqld.lib mysqlpp_d.lib
# Input
SOURCES += driver.cpp
######################################################################
# Automatically generated by qmake (2.01a) Tue Oct 4 13:35:54 2011
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += . C:\\mcpp\\mysql++\\lib C:\\msqlhome\\include
QMAKE_LIBDIR += . C:\\mcpp\\mysql++\\vc2008\\Debug C:\\msqlhome\\lib
LIBS += libmysqld.lib mysqlpp_d.lib
# Input
SOURCES += driver.cpp
To copy to clipboard, switch view to plain text mode
As you can see I have edited the .pro file to contain "INCLUDEPATH","QMAKE_LIBDIR"and "LIBS" variables.
Now I run
qmake mdb.pro
qmake mdb.pro
To copy to clipboard, switch view to plain text mode
and it runs ok. Then I type nmake and the app compiles and links to produce the executable mdb.exe
The problem is that on running the executable I get no output. (See attached image).
So I thought may be something is wrong with the mysql side of things.
So I wrote the following code:
#include <iostream>
int main(void)
{
std::cout << "Hello World" << std::endl;
}
#include <iostream>
int main(void)
{
std::cout << "Hello World" << std::endl;
}
To copy to clipboard, switch view to plain text mode
I ran this code through the "qmake -project" "qmake mdb.pro" "nmake" cycle of commands and all is well and an executable is produced.
But when I run this executable through the command prompt again I get no output.
WHat am I doing wrong?
Bookmarks