| Forum List • Thread List • Refresh • New Topic • Search • Previous • Next 1 | 1. Segmentation Fault with Win XP. #5030 | I am using Mingw 3.3.1, Dev C++ 4.9.8.10. And using WxWidgets 2.5.2. Recompiled it to enable ODBC support.
I am trying to create a Frame that allows me to type in data and upon clicking on a button.. a dialog box will pop up giving what I had typed.
I had an acesss violation (segmentation fault) whenever I click on the button. After some debugging... I isolate the error to this line.
wxString t2; t2.Append(theText->GetLineText(0));
In addition, sometimes the program also cannot compile giving error like cannot find -lopengl32-g3. It's only after trying to compile a few times can it actually compile. But it still crash upon clicking on the button.
The following is my header file. Is build on the default wxWindows template.
#ifndef __BASE_H #define __BASE_H
class MainApp: public wxApp { public: virtual bool OnInit(); };
class MainFrame: public wxFrame { public: MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size); void OnQuit(wxCommandEvent &event); void OnButtonSelect(wxCommandEvent &event); void OnFileOpen(wxCommandEvent &event); void OnAbout(wxCommandEvent &event); wxTextCtrl *theText; private: DECLARE_EVENT_TABLE() };
enum { ID_MAINWIN_QUIT = wxID_HIGHEST+1, ID_MAINWIN_OnButtonSelect, ID_MAINWIN_OnFileOpen, ID_MAINWIN_OnAbout };
#endif
this is the base.cpp
#include <wx/wxprec.h> #ifndef WX_PRECOMP #include <wx/wx.h> #endif
#include "base.h" #include "wx/db.h"
static const wxChar * TITLE = _T("Basic -step 3. Responding to events"); static const wxChar * FILETYPES = _T("Text Files|*.txt|" "C/C++ source files|*.cpp;*.cc;*.c|");
IMPLEMENT_APP(MainApp)
bool MainApp::OnInit() {
MainFrame *win = new MainFrame("Frame", wxPoint (100, 100), wxSize(450, 340)); win->Show(TRUE); SetTopWindow(win);
return TRUE; }
BEGIN_EVENT_TABLE(MainFrame, wxFrame)
EVT_MENU(ID_MAINWIN_QUIT, MainFrame::OnQuit) EVT_MENU(ID_MAINWIN_OnFileOpen, MainFrame::OnFileOpen) EVT_MENU(ID_MAINWIN_OnAbout, MainFrame::OnAbout) EVT_BUTTON(ID_MAINWIN_OnButtonSelect, MainFrame::OnButtonSelect)
END_EVENT_TABLE()
MainFrame::MainFrame(const wxString &title, const wxPoint &pos, const wxSize &size) : wxFrame((wxFrame *) NULL, -1, title, pos, size) {
wxMenu *FileMenu = new wxMenu; FileMenu->Append(ID_MAINWIN_OnFileOpen,"& Open File"); FileMenu->Append(ID_MAINWIN_OnAbout,"& About"); FileMenu->AppendSeparator(); // a line that seperate items into logical group FileMenu->Append(ID_MAINWIN_QUIT, "&Quit"); wxMenuBar *MenuBar = new wxMenuBar; MenuBar->Append(FileMenu, "&File"); SetMenuBar(MenuBar); //???
CreateStatusBar(2); SetStatusText("Welcome!"); wxTextCtrl *Dcontrol = new wxTextCtrl(this,-1,"Enter your query here",wxPoint(225,20),wxSize(200,20),0,wxDefaultValidator, "Frame"); wxStaticText * dytext = new wxStaticText(this,-1,"Type your query=>", wxPoint(20,20),wxSize(80,80),0,"Frame"); wxButton * dybutton = new wxButton(this,ID_MAINWIN_OnButtonSelect,"Send",wxPoint(100,100),wxSize(-1,-1),0,wxDefaultValidator,"Frame");
}
void MainFrame::OnButtonSelect(wxCommandEvent& event) { wxString t2; t2.Append(theText->GetLineText(0)); //problem!!!! wxMessageDialog aboutDialog( this, t2, "About Queries", wxOK | wxCANCEL); aboutDialog.ShowModal(); }
void MainFrame::OnFileOpen(wxCommandEvent & WXUNUSED(event)) { // theText->LoadFile("data.txt"); wxFileDialog * openFileDialog = new wxFileDialog(this,"Open File","","",FILETYPES,wxOPEN,wxDefaultPosition); /* if (openFileDialog->ShowModal() == wxID_OK) { SetCurrentFilename(openFileDialog->GetFilename()); theText->LoadFuke(openFileDialog->GetFilename()); SetStatusText(GetCurrentFilename(),0); SetStatusText(openFileDialog->GetDirectory(),1); } */ } void MainFrame::OnAbout(wxCommandEvent & WXUNUSED(event)) { wxString t = TITLE; t.append( _T("\nDB 2001")); wxMessageDialog aboutDialog(this, t,"trying", wxOK|wxCANCEL); aboutDialog.ShowModal(); }
void MainFrame::OnQuit(wxCommandEvent & WXUNUSED(event)) { Close(TRUE); }
| 2. Re: Segmentation Fault with Win XP. #5031 | HAHA.
Syntax error.
manage to run it successfully. | Forum List • Thread List • Refresh • New Topic • Search • Previous • Next 1 |
|
|