网格1->;ClearGrid()&;wxGrid崩溃应用程序的其他参考资料 我试图在代码中的一个小SQLite演示项目中实现我的第一个WXGRID:C++中的块,(Linux MINT 18.1)。没有错误的构建

网格1->;ClearGrid()&;wxGrid崩溃应用程序的其他参考资料 我试图在代码中的一个小SQLite演示项目中实现我的第一个WXGRID:C++中的块,(Linux MINT 18.1)。没有错误的构建,c++,linux,wxwidgets,C++,Linux,Wxwidgets,但是,我在项目中对wxGrid的任何引用都会使应用程序崩溃。 下面是简单的代码和gdb结果。第一个爆炸的引用很简单:Grid1->ClearGrid() 任何建议,请尽量具体。这是因为您的函数中有一个本地未初始化的Grid1,它隐藏了您在构造函数中初始化的类成员。摆脱它,使用类成员。哪个版本的wx?您是自己建造的还是从回购协议安装的?如果你建立它-你是什么配置线?你是如何建立这个程序的?您是否使用了“-g”选项?请在调试模式下编译库和代码,并显示有用的回溯请接受有用/正确的答案,以便自动泵不会继

但是,我在项目中对wxGrid的任何引用都会使应用程序崩溃。 下面是简单的代码和gdb结果。第一个爆炸的引用很简单:
Grid1->ClearGrid()


任何建议,请尽量具体。

这是因为您的函数中有一个本地未初始化的
Grid1
,它隐藏了您在构造函数中初始化的类成员。摆脱它,使用类成员。

哪个版本的wx?您是自己建造的还是从回购协议安装的?如果你建立它-你是什么配置线?你是如何建立这个程序的?您是否使用了“-g”选项?请在调试模式下编译库和代码,并显示有用的回溯请接受有用/正确的答案,以便自动泵不会继续向上移动您的问题。
#include "wxForm1.h"
#include <wx/msgdlg.h>
#include <wx/wxsqlite3.h>
#include <wx/grid.h>

//(*InternalHeaders(wxForm1)
#include <wx/string.h>
#include <wx/intl.h>
//*)

//(*IdInit(wxForm1)
const long wxForm1::ID_TEXTCTRL1 = wxNewId();
const long wxForm1::ID_BUTTON1 = wxNewId();
const long wxForm1::ID_BUTTON2 = wxNewId();
const long wxForm1::ID_GRID1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(wxForm1,wxFrame)
    //(*EventTable(wxForm1)
    //*)
END_EVENT_TABLE()

wxForm1::wxForm1(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
    //(*Initialize(wxForm1)
    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    SetClientSize(wxSize(620,420));
    Move(wxDefaultPosition);
    SetBackgroundColour(wxColour(240,19,19));
    txtSQL = new wxTextCtrl(this, ID_TEXTCTRL1, _("SELECT * FROM customers;"), wxPoint(40,48), wxSize(304,29), 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
    Button1 = new wxButton(this, ID_BUTTON1, _("Using wxButtonClick"), wxPoint(40,104), wxSize(296,29), 0, wxDefaultValidator, _T("ID_BUTTON1"));
    Button2 = new wxButton(this, ID_BUTTON2, _("Open DB - Fill Grid"), wxPoint(40,144), wxSize(296,29), 0, wxDefaultValidator, _T("ID_BUTTON2"));
    Grid1 = new wxGrid(this, ID_GRID1, wxPoint(40,184), wxSize(544,168), 0, _T("ID_GRID1"));
    Grid1->CreateGrid(4,4);
    Grid1->EnableEditing(true);
    Grid1->EnableGridLines(true);
    Grid1->SetDefaultColSize(115, true);
    Grid1->SetDefaultCellFont( Grid1->GetFont() );
    Grid1->SetDefaultCellTextColour( Grid1->GetForegroundColour() );

    Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxForm1::OnButton1Click);
    Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxForm1::OnButton2Click);
    //*)
}

wxForm1::~wxForm1()
{
    //(*Destroy(wxForm1)
    //*)
}


void wxForm1::OnButton1Click(wxCommandEvent& event) //*** ->GetValue() test ***
{
    wxString sqlLine = txtSQL->GetValue();
    wxMessageBox(sqlLine);
}

void wxForm1::OnButton2Click(wxCommandEvent& event)
{
     wxGrid *Grid1;
  wxSQLite3Database* db = new wxSQLite3Database();

  wxString testDBName = wxGetCwd() + wxT("/database.db");
    db->Open(testDBName);

   wxSQLite3ResultSet Res = db->ExecuteQuery(wxString::Format(_("%s"),txtSQL->GetValue()));

  Grid1->ClearGrid();  // **** Causes Crash ****

    int count = 0;

    while (Res.NextRow())
    {
        Grid1->SetCellValue(count,0,wxString::Format(_("%s"),Res.GetAsString(0)) ) ;
        Grid1->SetCellValue(count,1,wxString::Format(_("%i"),Res.GetInt(1)) ) ;
        Grid1->SetCellValue(count,2,wxString::Format(_("%s"),Res.GetAsString(2)) ) ;
      //  Grid1->SetCellValue(count,3,wxString::Format(_("%s"),Res.GetAsString(3)) ) ;
        count++;
    }
}
(gdb) run
Starting program: /home/dan/Documents/wxW_Projs/wxSQLi_417/bin/Debug/wxSQLi_417 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
*** Caught unhandled unknown exception; terminating
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff50a1820 in ?? () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
(gdb) bt
#0  0x00007ffff50a1820 in ?? ()
   from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
Backtrace stopped: Cannot access memory at address 0x7fffffffdb88
(gdb)