I got a problem when using mysql connector with wxWidgets my program crashes right when I start debugging, but it gives no compiler errors.
Main.h
#ifndef __MAIN_H
#define __MAIN_H
#include <wx/frame.h>
#include <wx/textctrl.h>
#include <wx/button.h>
// Mysql
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
class MainApp: public wxApp
{
public:
virtual bool OnInit();
};
class MainFrame: public wxFrame
{
public:
// Kaikki PUBLIC ARVOIKSI!
MainFrame( const wxString & title, const wxPoint & pos, const wxSize & size );
void Exit(wxCommandEvent & event);
void ChangeLanguage(wxCommandEvent & event);
void Checklogin(wxCommandEvent & event);
DECLARE_EVENT_TABLE()
private:
wxMenuBar * MenuBar;
wxStaticBox * Box;
wxMenu * FileMenu;
wxMenu * OptionsMenu;
wxTextCtrl * NameControl;
wxTextCtrl * PasswordControl;
wxButton * LoginButton;
wxPanel * panel;
sql::Driver * driver;
sql::Connection * con;
sql::Statement * stmt;
sql::ResultSet * res;
int Kieli;
};
enum
{
LIST_Box = wxID_HIGHEST + 1,
MENU_Exit,
STATIC_Box,
MENU_ChangeLanguage,
TEXT_NameBox,
TEXT_PasswordBox,
BUTTON_Login,
STATUS_Bar
};
#endif
Main.cpp
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "Main.h"
#define MAX 255
BEGIN_EVENT_TABLE( MainFrame, wxFrame ) // Event table alkaa
EVT_MENU(MENU_Exit, MainFrame::Exit)
EVT_MENU(MENU_ChangeLanguage, MainFrame::ChangeLanguage)
EVT_BUTTON(BUTTON_Login, MainFrame::Checklogin)
END_EVENT_TABLE() // --.-- loppuu
IMPLEMENT_APP(MainApp)
bool MainApp::OnInit()
{
MainFrame * MainWin = new MainFrame(wxT("Test application!"), wxPoint(1,1), wxSize(540,380));
MainWin->Show(TRUE);
SetTopWindow(MainWin);
return TRUE;
}
MainFrame::MainFrame(const wxString & title, const wxPoint & pos, const wxSize & size)
: wxFrame((wxFrame*) NULL, -1, title, pos, size)
{
// Palkki
CreateStatusBar(1);
MenuBar = new wxMenuBar();
FileMenu = new wxMenu();
OptionsMenu = new wxMenu();
Kieli = 0;
// Menu
FileMenu->Append(MENU_Exit, wxT("&Lopeta ohjelma"), wxT("Lopettaa ohjelman"));
OptionsMenu->Append(MENU_ChangeLanguage, wxT("&Vaihda kieli (Käytössä Suomi)"), wxT("Vaihtaa kieltä"));
MenuBar->Append(FileMenu, wxT("Tiedosto"));
MenuBar->Append(OptionsMenu, wxT("Asetukset"));
SetMenuBar(MenuBar);
// Paneeli
panel = new wxPanel(this, wxID_ANY);
// Static box
Box = new wxStaticBox(panel, STATIC_Box, wxT("Kirjautuminen"), wxPoint( 20, 15 ), wxSize(300, 275 ), 0, wxT("Boxi"));
// Text boxit ja nappi
NameControl = new wxTextCtrl(panel, TEXT_NameBox, wxEmptyString, wxPoint(130,130), wxSize(170,25),0, wxDefaultValidator, wxT("NameBox"));
PasswordControl = new wxTextCtrl(panel, TEXT_PasswordBox, wxEmptyString, wxPoint(130,165), wxSize(170,25),wxTE_PASSWORD, wxDefaultValidator, wxT("PasswordBox"));
LoginButton = new wxButton(panel, BUTTON_Login, wxT("Kirjaudu"), wxPoint(200,220), wxSize(100,25),0,wxDefaultValidator, wxT("LoginButton"));
try
{
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "secret");
con->setSchema("c++");
stmt = con->createStatement();
res = stmt->executeQuery("SELECT Nimi FROM ukot");
while (res->next())
{
Box->SetLabel(wxT("Lol"));
}
delete res;
delete stmt;
con->close();
delete con;
} catch (sql::SQLException &e)
{
}
}
void MainFrame::Exit(wxCommandEvent & WXUNUSED(event))
{
Close(TRUE);
}
void MainFrame::ChangeLanguage(wxCommandEvent & WXUNUSED(event))
{
if ( Kieli == 0 )
{
Box->SetLabel(wxT("Login"));
// Eka menu
FileMenu->SetLabel(MENU_Exit, wxT("&Exit"));
FileMenu->SetHelpString(MENU_Exit, wxT("Quits the program"));
MenuBar->SetLabelTop(0,wxT("File"));
// Toka menu
OptionsMenu->SetLabel(MENU_ChangeLanguage, wxT("&Change language (English in use)"));
OptionsMenu->SetHelpString(MENU_ChangeLanguage, wxT("Changes the language"));
MenuBar->SetLabelTop(1, wxT("Options"));
delete LoginButton;
LoginButton = new wxButton(panel, BUTTON_Login, wxT("Login"), wxPoint(200,220), wxSize(100,25),0,wxDefaultValidator, wxT("LoginButton"));
Kieli = 1;
}
else
{
Box->SetLabel(wxT("Kirjautuminen"));
// Eka menu
FileMenu->SetLabel(MENU_Exit, wxT("&Lopeta ohjelma"));
FileMenu->SetHelpString(MENU_Exit, wxT("Lopettaa ohjelman"));
MenuBar->SetLabelTop(0,wxT("Tiedosto"));
// Toka menu
OptionsMenu->SetLabel(MENU_ChangeLanguage, wxT("&Vaihda kieli (Käytössä Suomi)"));
OptionsMenu->SetHelpString(MENU_ChangeLanguage, wxT("Vaihtaa kieltä"));
MenuBar->SetLabelTop(1, wxT("Asetukset"));
delete LoginButton;
LoginButton = new wxButton(panel, BUTTON_Login, wxT("Kirjaudu"), wxPoint(200,220), wxSize(100,25),0,wxDefaultValidator, wxT("LoginButton"));
Kieli = 0;
}
}
void MainFrame::Checklogin(wxCommandEvent & WXUNUSED(event))
{
}
Any help?