PDA

View Full Version : MSVSC++ QT and debugging



harleyskater
24th June 2010, 20:03
I have built a similar project in C++ in Visual Studios. I am trying to convert as much of this project as I can into QT because the enviornment in which this application is needed has expanded to MAC OS.

All of this compiles but I know there is an issue somewhere in the code becasue my query is not returning any rows. which brings the main issue. I can not for the life of me figure out how to set breakpoints in Visual Studios so I can see what is happening with my variables usename and password

Theres no real reason for me to post my code because my real question is about debugging but I thought there might be something other than a breakpoint that could be done to check the variable so I included it :P



#include "thewge.h"
#include "ui_thewge.h"
#include <QtGui/QApplication>
#include <QSignalMapper>
#include <QPushButton>
#include <windows.h>
#include <iostream>
#include "md5.h"
#include "mysql++.h"

TheWGE::TheWGE(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{

ui.setupUi(this);

QObject::connect(ui.LoginBtn, SIGNAL(clicked()), this, SLOT(login()));

}

TheWGE::~TheWGE()
{
//ui.usrLineEdit->clear();
//ui.pwdLineEdit->clear();
}

void TheWGE::login()
{

if (ui.usrLineEdit->text().trimmed().isEmpty() )
{
ui.usrLineEdit->setFocus();
}
else if (ui.pwdLineEdit->text().trimmed().isEmpty() )
{
ui.pwdLineEdit->setFocus();
}

mysqlpp::Connection con(false);

if (!con.connect("Database", "host", "username", "password"))
{
qApp->exit(0);

}

// Retrieve a subset of the sample stock table set up by resetdb
mysqlpp::Query query = con.query();

QString Qstr1 = ui.usrLineEdit->text();
QString Qstr2 = ui.pwdLineEdit->text();

char *acsUserName = new char[ Qstr1.length() + 1 ]; // + 1 for zero in the end of string
memcpy( acsUserName, Qstr1.toUtf8().constData(),Qstr1.length() );
char *acsPassword = new char[ Qstr2.length() + 1 ]; // + 1 for zero in the end of string
memcpy( acsPassword, Qstr2.toUtf8().constData(), Qstr2.length() );


query << "SELECT username, password FROM wge_db_user WHERE username = '" << acsUserName << "' and password = '" << md5(acsPassword) << "'";

mysqlpp::StoreQueryResult res = query.store();
mysqlpp::Row row;

delete []acsUserName;
delete []acsPassword;

if (res.num_rows() > 0)
{
qApp->exit(0);
//goodlogin - show new form and hide this form
}
else
{

//qApp->exit(0);
//badlogin
}

mysqlpp::Connection::thread_end();


return;
}

franz
24th June 2010, 21:01
Visual studio has plenty of debugging tools. Put your cursor on a line of code and press F9. It should give you a breakpoint.

Aside from that you should probably have the visual studio add-in installed.

squidge
24th June 2010, 23:21
Make sure the debugging helper is installed.

Make sure you are compiling in 'Debug' mode not 'Release' mode.

harleyskater
25th June 2010, 09:25
solution. after reinstalling 2005 and then installing 2008 and having the same problem. I ran across a page that said some things about how I should reconfigure with things like /ZI. I had posted the link earlier to that page, but my reply didn't post. after getting my break points to work! things got muchhhhhh easier and I have everything working now! thx

harleyskater
27th June 2010, 22:28
i set up a new project and ran into the same problem and couldn't remember how to fix it, so I looked it up again.

here it is incase someone else runs into this problem

step1
project properties->linker->debugging->generate debug info = YES
step2
project properties->c++->general->debug information->Program Database for Edit & Continue (/ZI)